Can I use Lists in R as a proxy to data frame having unequal number of columns? -
my understanding far data frame in r
has rectangular. not possible have data frame unequal column lengths. can use list
s in r
achieve this? pros , cons such approach?
you can use lists store whatever want, dataframes or other lists! can indeed assign different length vectors, or different objects. gives same functionality dataframes in can index using dollar sign:
> foolist <- list(a=1:12, b=1:11, c=1:10) > foolist$a [1] 1 2 3 4 5 6 7 8 9 10 11 12 > foodf <- data.frame(a=1:10, b=1:10, c=1:10) > foodf$a [1] 1 2 3 4 5 6 7 8 9 10
but numeric indexing different:
> foolist[[1]] [1] 1 2 3 4 5 6 7 8 9 10 11 12 > foodf[,1] [1] 1 2 3 4 5 6 7 8 9 10
as structure , printing method:
> foolist $a [1] 1 2 3 4 5 6 7 8 9 10 11 12 $b [1] 1 2 3 4 5 6 7 8 9 10 11 $c [1] 1 2 3 4 5 6 7 8 9 10 > foodf b c 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10
simply said dataframe matrix , list more of container.
a list meant keep sorts of stuff together, , dataframe usual data format (a subject/case each row , variable each column). used in lot of analyses, allows index scores of subject, can more easilly transformed , other things.
however if have unequal length columns doubt each row resembles subject/case in data. in case guess don't need of functionality of dataframes.
if each row resemble subject/case, should use na
missing values , use data frame.
Comments
Post a Comment