[R] Rbind with data frames -- column names question
Gregg Lind
lind1199 at umn.edu
Mon Mar 5 23:06:05 CET 2007
As part of my work, I am trying to append matrices onto data frames.
Naively I assumed that when rbinding a data.frame and matrix, the matrix
would be coerced and appended, keeping the names from the data frame.
Clearly, I am not fully understanding the process by which rbind works.
Example code:
> A<-data.frame(1,1,1); names(A)=letters[1:3] ; B<-matrix(0,2,3)
> rbind(A,B)
Error in match.names(clabs, names(xi)) : names do not match previous names:
V1, V2, V3
> rbind(A,as.data.frame(B))
Error in match.names(clabs, names(xi)) : names do not match previous names:
V1, V2, V3
Is there a "right" way to combine the two such that the both end up
having the same column names?
I have tried to understand the deparse.level argument of rbind, but it
doesn't seem to do what I'm asking.
Thank you for any help you can give.
Gregg
--
Gregg Lind, M.S.
Division of Epidemiology and Community Health
School of Public Health
University of Minnesota, United States
More information about the R-help
mailing list