To create a large list of different lengths of type integer and extract the id and values into a dataframe in R, you can use the following code:
main.r324 chars13 lines
In this code:
lapply
and sample
.id
and value
.id
column is created by repeating the indices of the list (from 1 to the length of the list) as many times as the length of the corresponding integer vector.value
column is created by unlisting the list of integers.The resulting dataframe will have two columns: id
and value
, where id
is the index of the original list and value
is the corresponding integer value.
This code can be used to create dataframes from lists of different lengths and types, not just integers.
Please note that this code requires the base
package in R, which is installed by default.
gistlibby LogSnag