r - Unlist data.frame column of individual lists and preserve each cell as a vector -
first time posting apologies if doesn't meet standards! i'm working on simulation in i'm using cut()
create ordinal variables drawn multivariate normal distribution. i'm attempting create data.frame using expand.grid()
containing of conditions , run mdply()
'sew together.' particular column in df df$k
, contains vectors of cut points fed cut()
:
n <- c(25,50) p <- c(0,.1) k <- list(c(-inf,0,inf), c(-inf,-1,1,inf)) factors <- list(n=n, p=p, k=k) df <- expand.grid(factors) fx <- function(n, p, k){ data <- mvrnorm(n,c(0,0),matrix(c(1,p,p,1),2,2)) x <- cut(data[,1],k) y <- cut(data[,2],k) dat <- cbind(x,y) }
my issue although table of conditions looks correct, df$k
list of 8 lists, , when fed mdply()
gives error: error: (list) object cannot coerced type 'integer'
(i'm assuming that's why error popping up.) i'd unlist each cell each cell vector c(-inf, 0, inf)
. df now, believe solve problem. unlist(df$k)
creates 1 long vector, , loses cuts need--unlist(df$k[[x]])
does trick, need each element of column.
here's code produces error:
test <- mdply(df, .fun = runsim) #runsim contains fx above , estimation function
Comments
Post a Comment