[R] find and
Ashta
sewashm at gmail.com
Sat Mar 18 14:51:35 CET 2017
Hi all,
I am trying to find a city that do not have the same "var" value.
Within city the var should be the same otherwise exclude the city from
the final data set.
Here is my sample data and my attempt. City1 and city4 should be excluded.
DF4 <- read.table(header=TRUE, text=' city wk var
city1 1 x
city1 2 -
city1 3 x
city2 1 x
city2 2 x
city2 3 x
city2 4 x
city3 1 x
city3 2 x
city3 3 x
city3 4 x
city4 1 x
city4 2 x
city4 3 y
city4 4 y
city5 3 -
city5 4 -')
my attempt
test2 <- data.table(DF4, key="city,var")
ID1 <- test2[ !duplicated(test2),]
dps <- ID1$city[duplicated(ID1$city)]
Ddup <- which(test2$city %in% dps)
if(length(Ddup) !=0) {
test2 <- test2[- Ddup,] }
want <- data.frame(test2)
I want get the following result but I am not getting it.
city wk var
city2 1 x
city2 2 x
city2 3 x
city2 4 x
city3 1 x
city3 2 x
city3 3 x
city3 4 x
city5 3 -
city5 4 -
Can some help me out the problem is?
Thank you.
More information about the R-help
mailing list