Remove the rows that have the same column A value but different column B value from df (but not vice-versa) in R -
I am trying to remove all the rows that have the same value in the "LAN" column of my dataframe but differ Value for my "ID" column (but not vice versa)
Using an example dataset:
is needed (dplyr) t < - Structure (list (ID = C (1L, 2L, 2L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L), LAN = Structure (C (1L, 2L, 3L, 4L, 4L, 5L, 5L, 5L, 6L, 1L, 7L) .Label = C ("a", "B", "c", "d", " E "," f "," g "), class =" factor "), value = c (0.22988498, 0.848989831, 0.538065821, 0.916571913, 0.304183372, 0.983348167, 0.356128559, 0.054102854, name = C (NA, -11 L)) , Names = c ("id", "lan", "value"), class = "data.frame", row.names = 0.400934593, 0.001026817, 0.488452667) code> I have 1 and 10 lines You have to get rid of them because they have the same lane (A) but they have different IDs.
I Have tried the following:
a <-t [(duplicated (T $ id)), c & lt; -a [duplicate (one $ lane) | duplicate (one $ lane) , Celest = TRUE,] D & L; -T [! (% C% lane in T $ LAN%),]
Thank you for your help!
< / Div>
and an alternate using dplyr :
t 2 & lt; -t% & gt;% group_by (LAN, id)% & gt;% abbreviation (value = sum (value))% & gt;% group_by (LAN)% & gt;% abbreviation (number = N ())% Select & gt;% Filters (number> 1)%>% & gt;% (LAN) & gt; T $ $% in% t2 $ lan,] ID LAN Value 2 2B 0.848 9 8 9 3 3 C 2 0.53806582 4 3D 0.916571 9 5 3D 0.30418337 6 4E 0.98334817 7 4E 0.35612856 8 4E 0.05410285 9 4F 0.4009345 9 11 4G 0.48845267
Comments
Post a Comment