В Thu, 18 Apr 2024 16:31:46 +0000 "Deramus, Thomas Patrick" <tdera...@mgb.org> пишет:
> Basically, each list contains a set of doubles, with the first > indicating a specific index (based on the 0 beginning python index), > and a certain value (e.g. 0.5). > > What I would like to do is generate set of columns based on the rang > of unique indexes of each nested list. e.g.: col_1, col_2, col_3, > col_4, col_5 It's possible to golf it down to something like the following: newcol <- t(sapply(tibble$nestedvals, \(x) { x <- simplify2array(x) ret <- numeric(5) ret[x[1,]] <- x[2,] ret })) ...which you can then rename and cbind() to your tibble. But the problem remains that the desired data structure has to be generated row by row and then transformed back into a column-oriented data structure. Do you need a sparse matrix? spec <- do.call(cbind, Map( \(row, cols) rbind(row, simplify2array(cols)), seq_along(tibble$nestedvals), tibble$nestedvals )) sparse <- Matrix::sparseMatrix(spec[1,], spec[2,], x = spec[3,]) -- Best regards, Ivan ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.