[R] problem with using subset from two different tables

Jim Lemon jim at bitwrit.com.au
Fri Jun 5 11:45:24 CEST 2009


venkata kirankumar wrote:
> Hi all,
>
> I am new to R-project my problem is I tried to get subset from two different
> tables its giving error
> but if i m tring for  geting results from one table its working
>
> actually i have to take values from two tables with applying different
> conditions on two tables like
>
>
> kk- is an object of one table and
> fk- is an object of another table
>
> here i have to get values  from these tables like
>
> subset(kk & fk,kk$Rmaxtgavcg > 1.256 & fk$rmaxtgavcg <
> 3.25,select=c(uniqueid))
>
> my doubt is, that if any thing like this expression is there in R-project or
> i have to go for two different subsets and then adding those two one after
> another with checking the common uniqueid's
>
>   
Hi Kiran,
I assume that your tables are data frames and have the same first 
dimension. If not,

subsetvector<-kk$Rmaxygavcg > 1.256 & fk$rmaxtgavcg < 3.25

will recycle the shorter of the two logical vectors, which is almost 
certainly not what you want.
 If they have the same first dimension, you could then combine the 
tables and get your result:

dupnames<-which(names(fk)%in%names(kk))
subset(cbind(kk,fk[,-dupnames]),subsetvector)

Jim




More information about the R-help mailing list