Stan Hopkins
2007-Sep-04 14:52 UTC
[R] data.frame loses name when constructed with one column
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?> dataout 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]) > data1data...1. 1 1 2 2 3 3> data1=data.frame(data[,1:2]) > data1out 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]]
jim holtman
2007-Sep-05 00:00 UTC
[R] data.frame loses name when constructed with one column
Try drop=FALSE:> xout 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?
Possibly Parallel Threads
- Extracting lists in the dataframe $ format
- System GMM yields identical results for any weighting matrix
- System GMM yields identical results for any weighting matrix
- error calling Winbugs using R2WinBugs to run a multi-level model
- How to read.table with “Hebrew” column names (in R)?