Re: [R] dataframes with only one variable

From: Richard M. Heiberger <rmh_at_temple.edu>
Date: Fri 13 Jan 2006 - 00:49:00 EST


> df1

  v1
1 1
2 2
3 3
4 4
> df1[,]

[1] 1 2 3 4
> df1[,1]

[1] 1 2 3 4
> df1[,,drop=F]

  v1
1 1
2 2
3 3
4 4
> df1[,1,drop=F]

  v1
1 1
2 2
3 3
4 4
> df1[1]

  v1
1 1
2 2
3 3
4 4
> df1[[1]]

[1] 1 2 3 4
>

For transfers from Excel to R using the "[put/get] R dataframe" commands, I think it is important always to use the drop=FALSE argument (as I assume you are doing in RExcel V1.55). The reason for this is to maintain a rigid relationship between the only partially compatible conventions of Excel and R.

For strictly within R use, the case is less clear. I have trained myself always (well 85% on the first try) to use the drop=FALSE argument when I care about the structure after the copy.

The tension between keeping the structure and demoting the structure predates data.frames. This was a design issue in matrices as well.
> tmp <- matrix(1:6,2,3)
> tmp

     [,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6
> tmp[1,]

[1] 1 3 5
> tmp[1,,drop=FALSE]

     [,1] [,2] [,3]
[1,] 1 3 5
>

Rich



R-help@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 Received on Fri Jan 13 01:16:09 2006

This archive was generated by hypermail 2.1.8 : Fri 13 Jan 2006 - 02:03:40 EST