[R] convert a text file into a list (of lists)

Assa Yeroslaviz frymor at gmail.com
Thu Apr 13 16:47:11 CEST 2017


Hi,

I have a text file i would like to read into a list structure in R.

the files is something like that (which might be describe as a list of data
frames):

[[1]]
                   NAME  MEM.SHIP
FBgn0037415 FBgn0037415 0.8035441
FBgn0010812 FBgn0010812 0.6579683
FBgn0265351 FBgn0265351 0.6443309

[[3]]
                   NAME  MEM.SHIP
FBgn0037227 FBgn0037227 0.9997242
FBgn0040682 FBgn0040682 0.9997242
[[9]]
                   NAME  MEM.SHIP
FBgn0026620 FBgn0026620 0.5241095
FBgn0263619 FBgn0263619 0.5420427
FBgn0263353 FBgn0263353 0.9812295
FBgn0037424 FBgn0037424 0.9793901
FBgn0037428 FBgn0037428 0.9779420
FBgn0037430 FBgn0037430 0.9540148
FBgn0004777 FBgn0004777 0.8962534
FBgn0004778 FBgn0004778 0.9810570
...

I would like it to have a list structure like that at the end:

> str(INPUT)
List of 3
 $ : Factor w/ 223 levels "GENE1",..: 194 129 222 213 42 130 45 131 132 133
...
 $ : Factor w/ 210 levels "GENE4",..: 185 109 110 146 171 175 111 17 112
209 ...
 $ : Factor w/ 343 levels "GENE7",..: 27 296 326 228 229 263 19 39 230 26

I am reading the file in with scan, but I just get a character vector of
all the elements together.
I was wondering if there is a way to split the text file into a list by the
pattern [[.*]] and than extract only the first  column from each data frame.

thanks in advance
Assa

	[[alternative HTML version deleted]]



More information about the R-help mailing list