Hi friends, I have got a list where each element might have variable number of members. $`4213` [1] "214077_x_at" $`164832` [1] "225996_at" "235977_at" $`339010` [1] NA $`23410` [1] "221562_s_at" "221913_at" "49327_at" $`285386` [1] "229764_at" $`2099` [1] "205225_at" "211233_x_at" "211234_x_at" "211235_s_at" [5] "211627_x_at" "215551_at" "215552_s_at" "217163_at" [9] "217190_x_at" I want to integrate this list in a matrix format like this : 4213 "214077_x_at" 164832 "225996_at" 164832 "235977_at" 339010 NA 23410 "221562_s_at" 23410 "221913_at" 23410 "49327_at" .... Any idea how can I make such type of matrix ? Thanks, Vickie [[alternative HTML version deleted]]
On Jul 20, 2011, at 5:04 PM, Vickie S wrote:> > Hi friends, > I have got a list where each element might have variable number of > members. > $`4213` > [1] "214077_x_at" > > $`164832` > [1] "225996_at" "235977_at" > > $`339010` > [1] NA > > $`23410` > [1] "221562_s_at" "221913_at" "49327_at" > > $`285386` > [1] "229764_at" > > $`2099` > [1] "205225_at" "211233_x_at" "211234_x_at" "211235_s_at" > [5] "211627_x_at" "215551_at" "215552_s_at" "217163_at" > [9] "217190_x_at" >If you had posted the output from dput(head(this_list)) it would have made testing easier. Observe: > dput(this_list) structure(list(`4213` = "214077_x_at", `164832` = c("225996_at", "235977_at"), `339010` = NA, `23410` = c("221562_s_at", "221913_at", "49327_at"), `285386` = "229764_at"), .Names = c("4213", "164832", "339010", "23410", "285386")) So now all one need to do is stick a "<-" in between the name and the structure expression and one has a "reproducible example". (testing on these first four entries) > matrix( c( rep(names(this_list), sapply(this_list, length)) , + unlist(this_list) + ) , ncol=2) [,1] [,2] [1,] "4213" "214077_x_at" [2,] "164832" "225996_at" [3,] "164832" "235977_at" [4,] "339010" NA [5,] "23410" "221562_s_at" [6,] "23410" "221913_at" [7,] "23410" "49327_at" [8,] "285386" "229764_at"> I want to integrate this list in a matrix format like this : > > 4213 "214077_x_at" > 164832 "225996_at" > 164832 "235977_at" > > 339010 NA > 23410 "221562_s_at" > 23410 "221913_at" > 23410 "49327_at"You cannot mix modes in matrices. They all need to be "character".> .... > > Any idea how can I make such type of matrix ? > > > Thanks, > Vickie > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org 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.David Winsemius, MD West Hartford, CT
Filipe Leme Botelho
2011-Jul-20 21:39 UTC
[R] RES: Question about converting list items in matrix
An embedded message was scrubbed... From: "Filipe Leme Botelho" <filipe.botelho at vpar.com.br> Subject: RES: [R] Question about converting list items in matrix Date: Wed, 20 Jul 2011 18:39:45 -0300 Size: 3105 URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110720/eda6bda6/attachment.mht> -------------- next part -------------- "This message and its attachments may contain confidential and/or privileged information. If you are not the addressee, please, advise the sender immediately by replying to the e-mail and delete this message." "Este mensaje y sus anexos pueden contener informaci?n confidencial o privilegiada. Si ha recibido este e-mail por error por favor b?rrelo y env?e un mensaje al remitente." "Esta mensagem e seus anexos podem conter informa??o confidencial ou privilegiada. Caso n?o seja o destinat?rio, solicitamos a imediata notifica??o ao remetente e exclus?o da mensagem."