[R] subset problem
reeyarn
reeyarn at gmail.com
Fri Mar 30 10:24:41 CEST 2012
Thank you so much, Peter and Andrija :)
On Thu, Mar 29, 2012 at 1:44 PM, peter dalgaard <pdalgd at gmail.com> wrote:
> %in% is your friend
> mysub <- subset(df, type %in% type_list, select=c(name,type))
> or
> mysub <- df[df$type %in% type_list, c("name","type")]
> The latter is slightly safer if you can't be sure that df doesn't contain a column called type_list.
On Thu, Mar 29, 2012 at 1:45 PM, andrija djurovic <djandrija at gmail.com> wrote:
> Hi. You can try this:
> You can also use sqldf package and subset data frames usign sql statements:
> library(sqldf)
> df <- data.frame(x1=1:10, type=10:1)
> type_list <- data.frame(index=seq(1,10,by=2))
> sqldf("select df.*
> from df
> where df.type in (select * from type_list)")
> Andrija
More information about the R-help
mailing list