[R] types of vectors / lists

From: <a9804814_at_unet.univie.ac.at>
Date: Wed, 05 Mar 2008 20:56:27 +0100


I am an advanced user of R. Recently I found out that apparently I do not fully understand vectors and lists fully Take this code snippet:

T = c("02.03.2008 12:23", "03.03.2008 05:54") Times = strptime(T, "%d.%m.%Y %H:%M")

Times                 # OK
class(Times)          # OK
is.list(Times)        # sort of understand and not understand that
length(Times)         # 9 ??? why is it length(Times[1]) ??

Times[1] # OK
Times[[1]] # Wrong

so Times is a vector-style thing of a non-atomic type. What puzzles me is first that is.list returns true, and more importantly that the length-query returns the length of the first object of that apparent list and not how many elements are contained (i.e., I would have expected 2 as result - and I do not know what syntax to use in order to get the 2).

Moreover, if the whole thing is part of a data.frame:

DFTimes = as.data.frame(Times)
length(DFTimes$Times) # OK, 2

then everything is as expected.

Could anyone please clearify why is.list returns true and why length in the first example returns 9 ? Is it that c() makes a list if the objects to be concatenated are not representable directly by atomic types ?


R-help_at_r-project.org 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. Received on Wed 05 Mar 2008 - 20:03:20 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 05 Mar 2008 - 21:30:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive