Skip to content
Prev 285678 / 398502 Next

R's list data structure

HI Ajay,
On Fri, Feb 17, 2012 at 3:20 PM, Ajay Askoolum <aa2e72e at yahoo.co.uk> wrote:
In your particular case, where all list components are the same length and are
associated with each other in order, a special type of list called a data frame
is easier to work with.

weekProfile<- data.frame(dow=dayOfWeekName,dowI=dayOfWeekOrdinal,dowW=dayOfWeekWorkDay)
dow dowI  dowW
1 Mon    1  TRUE
2 Tue    2  TRUE
3 Wed    3  TRUE
4 Thu    4  TRUE
5 Fri    5  TRUE
6 Sat    6 FALSE
7 Sun    0 FALSE

I'm not sure what kind of conditional you want, but this can easily be done
with subset() or [
dow dowI dowW
1 Mon    1 TRUE
2 Tue    2 TRUE
3 Wed    3 TRUE
4 Thu    4 TRUE
5 Fri    5 TRUE

A regular list is excellent for holding diverse kinds of data, for example 10
lm() objects, or a series of data frames.

In a list, the third element of component 1 may not have anything whatsoever
to do with the third element of component 2.

In a data frame, rows are related.
Data frame.