Moving a list in a .csv file in R; cannot use `unlist` properly
csv, list, r
Solution
You need to protect the `list` structure by using `I()` (which is more commonly used in `formula` objects)...
data.frame( Number = 1:length(L) , Type = I(L) )
# Number Type
#1 1 Orks, Eldar
#2 2 Nid, Tau
`I()` is a function which is used to...
Change the class of an object to indicate that it should be treated ‘as is’
Problem
I produced in R the list L, with ``` L <- list() L[[1]] <-cbind ("Orks", "Eldar") L[[2]] <-cbind ("Nid", "Tau") ``` and output ``` > L [[1]] [,1] [,2] [1,] "Orks" "Eldar" [[2]] [,1] [,2] [1,] "Nid" "Tau" ``` I would like to write a .csv file with the following output ``` Number Type 1 Orks, Eldar 2 Nid, Tau ``` i.e. transferring the list component L[[i]] to the i-th row of the file, with the above splitting and column names. I began to process the list by using ``` LL <- data.frame(matrix(unlist(L), nrow=2) ) ``` but the output does not convince me, as I do not know how to bind the entries on the same row of the columns of `LL`, before sending them to the .csv file. Is there a brute-force way to arrive at the .csv structure above, instead of playing around with `unlist` and its results? I thank you very much!