r - How to convert list file to matrix -
I have a list file as the following:
& gt; Results [[1]] [[1]] [[1]] [[1]] [[1]] [[1]] [[1]] [[1]] [[1]] [[1] [1] "1" "swelling" "37.5" "a" "b" [6] "f" [[1]] [[1]] [2]] [[1]] [[1]] [ [2] [1] [1] "1" "opopassis" "37.5" "c" "g" "h" [1]] [[1]] [[3]] [[1]] [[3] ] [1] "1" "Repair" "25" "A" "H" [2]] [2]] [[1]] [2]] [[1]] [[1] ]] [[2]] [[1]] [1]] [[1]] [1] "2" "swelling" "20" "f" [[2]] [[1]] [[2] ]] [[2]] [[1]] [[2]] [[1]] [1] "2" "apoposis" "40" "g" "h" [[2]] [[1]] [[3]] [[2]] [[1]] [[3]] [[1]] [1] "2" "repair" "20" "H" In addition, it is the Outlook for dput function:
dput (list) list (list (list (list (list (c ("1" (c ("1", "apoptosis" , "37.5", "c", "jee", "h"), list ("swelling", "37 List (list (list (list "C" ("2", "swelling", "20", list (C ("1", "5", "A", "B", "F" List (list "list" (list "list", "c" ("2", "apoptosis", "40", "g", "rep", "25", "a", "h"))), list (list (list "f") "H"), list (C ("2", "Repair", "20", "H" "(list (list (" C "(" 3 "," swelling "," 25 "," F ")) , List (list (list (list (list (list "(" ("3", "apoposis", "25", "c"), list (c ("3", "repair", "0")) 4 "," inflam list (c ("4", "apoptosis", "33.33333333333", "g", "h"), list (c), list (c ("4", "b", "a I I want to make matrix like route> Wide gene 1 inflammation 37.5 A, B, F1 apoptosis 37.5 C, G, H1 repair 25 A, H2 swelling 20 F 2 apoposis 40 g, H2 repair 20H Is there any trick for this? The gene column contains gene in various numbers.
I probably like this hand on the shadow above But there is also an optional recurring implementation that does not fix the number of unlink, that is, it can control different depth in the list of lists. It crosses only the tree until it finds an element other than list and makes some specific formatting on it, and finally rbinds all of these same matrix To: recurse.format & lt; - function (x, format = function (z) {c (z [1: 3], ifelse (length (z)> 3, paste (z [4: length (z), {collapse = ","} , NA))}} {if (class (x) == "list") {do.call ("rbind", lapply (x, fun = recurse.format))} else {format (x)}} mat; Printed (mat) number - Jane with path weight [recapture] colnames (mat) & lt; - c ("number", "path", "weight", "gene") print (mat) 1, "1" "swelling" "37.5" "A, B, F" [2,] "1", "epochosis" "37.5" "c, g, h" [3 [5], "2" "apoptosis "" 40 "" G, H "" 1 "" Repair "" 25 "" A, H "[4,]" 2 "" Swelling "" 20 "[6,]" 2 "" Repair "" 20 " H "[7,]" 3 "" swelling "" 25 "" F "[8,]" 3 "" opopassis "" 25 "" C "[9," A ", A, F [11,]" 4 "Eopop" "A", "A", "3333333333333" "G, H" "3" "Repair" "0" NA [10,] "4" "Swelling" "50" [12,] "4" "Repair" "33.3333333333333" "
Comments
Post a Comment