[R] List of List in Data Frame

Gundala Viswanath gundalav at gmail.com
Tue Feb 1 02:45:39 CET 2011


Dear sirs,

I have a data that is generated like this:

> dat1 <- data.frame(V1 = rep(1, 5), V2 = sample(c(40:45), 5))
> dat2 <- data.frame(V1 = sample(c(0,1), 5, replace = TRUE), V2 = sample(c(40:45), 5, replace = TRUE))

What I want to do is to obtain a data frame that contain list of list.

> hiv
$hiv.dat1
$hiv.dat1$V1[[1]]
[1] 1 1 1 1 1

$hiv.dat1$V2[[1]]
[1] 41 42 43 40 44


$hiv.dat2
$hiv.dat2$V1[[1]]
[1] 0 1 1 0 0

$hiv.dat2$V2[[1]]
[1] 42 43 40 44 43

But why this line of command failed to create that?

> hiv <- list(hiv.dat1 = as.list(dat1), hiv.dat2 = as.list(dat2))

Especially it gives  "$hiv.dat1$V1" instead of "$hiv.dat1$V1[[1]]".

How can we correct that?
I need this particular data structure required for a specific package (ROCR).

- G.V.



More information about the R-help mailing list