Hi netters, Suppose I have two data frames X and Y. X has three colnames A, B and C. Y has three colnames A,B and D. I want to combine them into one matrix, joining the rows having the same A and B values (X$A==Y$A and X$B = Y$B). So the resulting dataframe has four variables/columns: A,B,C and D. I was wondering what's the best way to do it in R. Could anyone give me some advice? Thanks! Zhihua Li _________________________________________________________________ ÊÖ»úÒ²ÄÜÉÏ MSN ÁÄÌìÁË£¬¿ìÀ´ÊÔÊÔ°É£¡ [[alternative HTML version deleted]]
Henrique Dallazuanna
2008-Jan-26 20:22 UTC
[R] An R clause to bind dataframes under certain contions
Try this: merge(x, y, all=T) On 26/01/2008, zhihuali <lzhtom at hotmail.com> wrote:> > Hi netters, > Suppose I have two data frames X and Y. X has three colnames A, B and C. Y has three colnames A,B and D. > > I want to combine them into one matrix, joining the rows having the same A and B values (X$A==Y$A and X$B = Y$B). So the resulting dataframe has four variables/columns: A,B,C and D. > > I was wondering what's the best way to do it in R. Could anyone give me some advice? > > Thanks! > > Zhihua Li > > > _________________________________________________________________ > ????? MSN ?????????? > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help at 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. > >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Wensui Liu
2008-Jan-26 20:37 UTC
[R] An R clause to bind dataframes under certain contions
Hi, Huali, there is another way to do so library(sqldf) wanted <- sqldf("select * from X inner join Y on X.A = Y.A and X.B = Y.A") 2008/1/26 zhihuali <lzhtom at hotmail.com>:> > Hi netters, > Suppose I have two data frames X and Y. X has three colnames A, B and C. Y has three colnames A,B and D. > > I want to combine them into one matrix, joining the rows having the same A and B values (X$A==Y$A and X$B = Y$B). So the resulting dataframe has four variables/columns: A,B,C and D. > > I was wondering what's the best way to do it in R. Could anyone give me some advice? > > Thanks! > > Zhihua Li > > > _________________________________________________________________ > ????? MSN ?????????? > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help at 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. > >-- ==============================WenSui Liu Statistical Project Manager ChoicePoint Precision Marketing (http://spaces.msn.com/statcompute/blog) ===============================
Have a look at rbind.fill() in the reshape library. This will return a data.frame not a matrix but you can always convert it to a matrix. --- zhihuali <lzhtom at hotmail.com> wrote:> > Hi netters, > Suppose I have two data frames X and Y. X has three > colnames A, B and C. Y has three colnames A,B and D. > > I want to combine them into one matrix, joining the > rows having the same A and B values (X$A==Y$A and > X$B = Y$B). So the resulting dataframe has four > variables/columns: A,B,C and D. > > I was wondering what's the best way to do it in R. > Could anyone give me some advice? > > Thanks! > > Zhihua Li > > >_________________________________________________________________> ?????????? MSN ???????????????????? > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help at 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. >
Possibly Parallel Threads
- Comparison of aggregate in R and group by in mysql
- locate the rows in a dataframe with some criteria
- how to use a function in aggregate which accepts matrix and outputs matrix?
- sort a data matrix by all the values and keep the names
- Error: evaluation nested too deeply when doing heatmap with binary distfunction