Thank you so much, Peter and Andrija :)

On Thu, Mar 29, 2012 at 1:44 PM, peter dalgaard <pda...@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 <djandr...@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

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to