[R] names error message
Sarah Goslee
sarah.goslee at gmail.com
Tue Dec 3 00:19:28 CET 2013
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
More information about the R-help
mailing list