Re: [R] merge for data.frame and matrix

2010-05-13 Thread David Winsemius
On May 13, 2010, at 5:34 AM, Dennis Murphy wrote: Hi: You've got to convert m to a data frame first: Well, that would be one way, but it is not true that it is necessary. The Details section of the help page for merge says that row,names is an acceptable "by" specification, so without th

Re: [R] merge for data.frame and matrix

2010-05-13 Thread Dennis Murphy
Hi: You've got to convert m to a data frame first: > m <- data.frame(m) > m$nms <- rownames(m) > merge(df, m, by.x = 'col1', by.y = 'row.names') col1 col2.x col1 col2.y 1 kk 68 9 2 kk 38 9 HTH, Dennis On Wed, May 12, 2010 at 5:03 PM, Yuan Jian wrote: > Hello,

[R] merge for data.frame and matrix

2010-05-13 Thread Yuan Jian
Hello, how to merge a data.frame and a matrix by one column in the data.frame and rownames of the matrix? df <- data.frame(col1=c("kk","yy","kk"),col2=c(6,4,3)) > df   col1 col2 1   kk    6 2   yy    4 3   kk    3 m<-matrix(c(3,8,56,9), nrow=2, dimnames = list(c("aa","kk"),c("col1","col2"))) > m