How to make a dataframe with lists or vectors as its elements This is something I have been wondering for ages but I am never able to get an answer.

I am trying to understand how to make a dataframe in R, where each element of the dataframe is itself a vector or a matrix.

For example, lets say we have a regular vector V with elements being real numbers.

Then to acess any number we would have

V[3] which would give the third element of said vector.

Now I want to know how to do this with say a dataframe D,

where each element of the dataframe is itself a vector or matrix, so that say

D[3] is not a real number, but a vector.

How can this be done in R?

Thanks all
This can be done like this:

library(data.table)

dt&lt;-data.table(x=c("a","b","c"), y= lapply(1:3, function(x) matrix(rep(x, x*x), nrow=x)))

dt[2, y]

#[[1]]
#     [,1] [,2]
#[1,]    2    2
#[2,]    2    2

dt[2, `:=`(y=list(c(1,2,3)))]
dt[2,y]

#[[1]]
#[1] 1 2 3


```