[R] where did the column names go to?

pdb philb at philbrierley.com
Thu Jul 29 12:28:20 CEST 2010


I've just tried to merge 2 data sets thinking they would only keep the common
columns, but noticed the column count was not adding up. I've then
replicated a simple example and got the same thing happening.

q1. why doesn't 'b' have a column name?

q2. when I merge, why does the new column 'y' have all values as 5.1?

Thanks in advance,

Mr. confused
 

> a <- iris[,]
> b <- iris[,1]
> 
> head(a)
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa
> head(b)
[1] 5.1 4.9 4.7 4.6 5.0 5.4
> 
> c <-merge(a,b)
> head(c)
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species   y
1          5.1         3.5          1.4         0.2  setosa 5.1
2          4.9         3.0          1.4         0.2  setosa 5.1
3          4.7         3.2          1.3         0.2  setosa 5.1
4          4.6         3.1          1.5         0.2  setosa 5.1
5          5.0         3.6          1.4         0.2  setosa 5.1
6          5.4         3.9          1.7         0.4  setosa 5.1
> 
> NCOL(a)
[1] 5
> NCOL(b)
[1] 1
> NCOL(c)
[1] 6
> 

-- 
View this message in context: http://r.789695.n4.nabble.com/where-did-the-column-names-go-to-tp2306267p2306267.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list