[R] data.frame loses name when constructed with one column
jim holtman
jholtman at gmail.com
Wed Sep 5 02:00:08 CEST 2007
Try drop=FALSE:
> x
out pred1 predd2
1 1 2.0 3.0
2 2 3.5 5.5
3 3 5.5 11.0
> x[,1]
[1] 1 2 3
> data.frame(x[,1])
x...1.
1 1
2 2
3 3
> data.frame(x[,1, drop=FALSE])
out
1 1
2 2
3 3
>
On 9/4/07, Stan Hopkins <stanhopkins at comcast.net> wrote:
> Not sure why the data.frame function does not capture the name of the column field when its being built with only one column.
>
> Can anyone help?
>
>
>
> > data
> out pred1 predd2
> 1 1 2.0 3.0
> 2 2 3.5 5.5
> 3 3 5.5 11.0
> > data1=data.frame(data[,1])
> > data1
> data...1.
> 1 1
> 2 2
> 3 3
> > data1=data.frame(data[,1:2])
> > data1
> out pred1
> 1 1 2.0
> 2 2 3.5
> 3 3 5.5
> > sessionInfo()
> R version 2.5.1 (2007-06-27)
> i386-pc-mingw32
>
> locale:
> LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
>
> attached base packages:
> [1] "stats" "graphics" "grDevices" "utils" "datasets" "methods"
> [7] "base"
> >
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
More information about the R-help
mailing list