[R] selections of data by one variable
Christoph Lehmann
christoph.lehmann at gmx.ch
Wed May 4 18:23:54 CEST 2005
test <- data.frame(cbind(1:10,11:20))
names(test) <- c("a", "b")
test[test$b == 17,]
test[test$b %in% c(13, 15, 17),]
Tu Yu-Kang wrote:
> Dear R experts,
>
> My problem is as follows:
>
> Suppose I have a data frame d comprising two variable a<-c(1:10) &
> b<-c(11:20).
>
> I now want to select a subgroup according the values of b.
>
> I know if I just want to select, say, b=17, I can use f<-d[d$b==17] and
> R will give me
>> f
> a b
> 7 7 17
>
> However, if now I want to select a subgroup according to
> b==e<-c(13,15,17), then the same syntx doesn't work.
>
> What is the correct way to do it? My data have more than one million
> subjects, and I want to select part of them according to their id numbers.
>
> Your help will be highly appreciated.
>
> Best regards,
>
> Yu-Kang
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
More information about the R-help
mailing list