Skip to content
Prev 67855 / 398506 Next

Getting subsets of a data frame

I am reading as fast as I can! Just started with R five days ago.

I found the following in the documentation:

"Although the default for 'drop' is 'TRUE', the default behaviour when
only one _row_ is left is equivalent to specifying 'drop = FALSE'.  To
drop from a data frame to a list, 'drop = FALSE' has to (sic)
specified explicitly."

I think the exception mentioned in the first sentence is the reason
for my confusion.

I also think the second sentence is wrong and should have 'TRUE'
instead of 'FALSE'.

While it is true that a data frame is a list, it is not a list of
numbers, but rather a list of columns, which, if I understand
correctly, can be either vectors or matrices. So regardless of the
value assigned to 'drop' the returned object is a list.

When I asked "why isn't sw[1, ] a list?" I should have asked instead
"why isn't sw[1, ] a list of vectors?"

I did some experiments with a data frame a, where the columns are
vectors (no matrix columns):
[1] TRUE
[1] TRUE                     (did not sop being a data frame)
[1] TRUE                     (but it is a list)
[1] FALSE                   (no longer a data frame)
[1] TRUE                     (but it is a list)
[1] TRUE                    (still a data frame)
[1] TRUE                    (but it is a list)

I also tried:
$dates.num
[1] 477032400
dates.num
3 477032400  (notice the row name)
$names
[1] "dates.num"

$class
[1] "data.frame"

$row.names
[1] "3"
$names
[1] "dates.num"

FS
On 4/16/05, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote: