[R] How to find data that includes certain values

Den d.kazakiewicz at gmail.com
Sat Jan 22 02:04:30 CET 2011


Hello
Consider following dataframe named df


var1	var2 	var3
3771	354	565
654654	963	6677
775	147	657754

df <- read.table('clipboard', header = TRUE)
df
#find indexes with '77' in var 1
myIndexes <- grep( glob2rx("*77*"), df$var1)
myIndexes
#find actual values of seach above
myValu <- grep( glob2rx("*77*"), df$var1, value=TRUE)
myValu
#find all '77' in entire dataframe
all77 <- lapply(df, function(x)grep( glob2rx("*77*"), x, value=TRUE))
all77
#OR indexes
all77ind <-lapply(df, function(x)grep( glob2rx("*77*"), x))
all77ind


Hope that helps
With best regards
Denis



More information about the R-help mailing list