[R] converting a list to a data.frame
Hello, I have a list with n numerical components of different length (3, 4 or 5 values in each component of the list); I need to export this as a text file where each component of the list will be a row and where missing values should fill in the blanks due to the different lengths of the components of the list. I think that as a first step I should convert my list to a data frame, but this is not such a simple task to accomplish: I was thinking of the following for loop: X-data.frame(1,1,1,1,1); for (i in 1:length(list)) { X[i,]-unlist(list[[i]]); } Unfortunately, when the number of elements in the components of the list are lower than 5 (maximum), I get errors or undesired results. I also tried with rbind(), but again I couldn't manage to make it accept rows of different length. Does anybody have any suggestions? Working with lists is very nice, but I still have to learn how to transfer them to text files for external use. Thnak you, Filippo Biscarini Wageningen University [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list 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.
[R] Merge: how can I keep discarded values?
Good morning, I am merging two datasets and I would like to save the non-matching rows in a separate file. The problem is how to retrieve the non-matching rows in R. Example: DATASET A code nomi A1 Franco A2 Mario A3 Andrea A4 Sandro A5 Luca DATASET B codebook A1Guerra e Pace A1 Storia di Roma A2 La coscienza di Zeno A4 Ivanhoe A1 I Malavoglia A2 Jude the obscure when merging two rows are unmatched: A3 Andrea A5 Luca And these are exactly the rows I would like to store in a separate file/dataset. I tried with: AM-merge(A,B,all=TRUE) A1-AM[is.na(AM$book),] to keep the rows with a NA value in the book column. The problem is that this works in this particular case, but in real situations I might have other NA values in the book column, not resulting from the merge operation, but that are real missing values: in such cases, with the is.na command I would retrieve also thiese unneeded rows. Can someone suggest a better strategy to tackle this problem? Regards, Filippo Biscarini Wageningen University The Netherlands [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list 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.