An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20131202/836e3c05/attachment.pl>
names error message
3 messages · Julie Royster, Sarah Goslee, William Dunlap
Hi Julie,
On Mon, Dec 2, 2013 at 3:38 PM, Julie Royster <jsdroyster at nc.rr.com> wrote:
Hello wise R folks, I ran a job to combine 2 dataframes using rbind. I received this error message that the names were not the same Error in match.names(clabs,names(xi)): names do not match previous names BUT when I entered this statement Identical (names(data1[[1]]),names(data2[[2]]) )
I'm not sure what you think you're comparing here:
data1 <- data.frame(a=1:3, b=4:6, c=7:9)
data2 <- data.frame(A=11:13, B=14:16, C=17:19)
row.names(data1) <- c("A", "B", "C")
identical (names(data1[[1]]),names(data2[[2]]) )
[1] TRUE I initially thought you were comparing row names to column names, but that's also not right. Instead you're taking the first list element of data1 and comparing its name to that of the second list element of data2, but extracting them in a way that removes the names:
data1[[1]]
[1] 1 2 3
data2[[2]]
[1] 14 15 16
names(data1[[1]])
NULL
names(data2[[2]])
NULL Compared to:
names(data1[1])
[1] "a"
names(data2[2])
[1] "B" Instead, you need to look at the column names of each, which are most conveniently accessed with colnames(data1) and colnames(data2)
R responded TRUE to this query, indicating the names are identical So I am baffled. visually checking each dataset using str they look the same, and R says they are the same when queried, But I still get the error when I give this command newname <- rbind (data1,data2) Any ideas?
Best idea of all: provide a reproducible example, because otherwise there's no way to tell. dput(head(data1)) and dput(head(data2)) and paste that into your email. Sarha
Sarah Goslee http://www.functionaldiversity.org
I ran a job to combine 2 dataframes using rbind. I received this error message that the names were not the same Error in match.names(clabs,names(xi)): names do not match previous names
The column names of the data.frames given to rbind must all be
permutations of one another. E.g.,
> rbind(data.frame(A=1:3,B=11:13), data.frame(B=14:17, A=4:7))
A B
1 1 11
2 2 12
3 3 13
4 4 14
5 5 15
6 6 16
7 7 17
but not
> rbind(data.frame(A=1:3,B=11:13), data.frame(B=14:17, C=104:107))
Error in match.names(clabs, names(xi)) :
names do not match previous names
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Julie Royster Sent: Monday, December 02, 2013 12:39 PM To: r-help at r-project.org Subject: [R] names error message Hello wise R folks, I ran a job to combine 2 dataframes using rbind. I received this error message that the names were not the same Error in match.names(clabs,names(xi)): names do not match previous names BUT when I entered this statement Identical (names(data1[[1]]),names(data2[[2]]) ) R responded TRUE to this query, indicating the names are identical So I am baffled. visually checking each dataset using str they look the same, and R says they are the same when queried, But I still get the error when I give this command newname <- rbind (data1,data2) Any ideas? THANKS! Julie [[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.