[R] list entries file into a list

Liaw, Andy andy_liaw at merck.com
Thu Jan 26 14:14:41 CET 2006


The following might be what you want (replace "clipboard" with your
filename):

> mylist <- strsplit(readLines("clipboard"), ":")
> nm <- sapply(mylist, "[", 1)
> mylist <- lapply(mylist, "[", -1)
> names(mylist) <- nm
> mylist <- lapply(mylist, function(s) strsplit(s, ",")[[1]])
> mylist
$entry0001
[1] "AB0032"  "CF32134" "DF34334"

$entry0002
[1] "AB0033"

$entry0003
[1] "AB0032"   "CF32134"  "DF34334"  "DD343434" "DD34222" 

$entry0004
[1] "AB0032"  "CF32134"

Andy

From: Albert Vilella
> 
> Hi all,
> 
> I have a file of this kind:
> 
> entry0001:AB0032,CF32134,DF34334
> entry0002:AB0033
> entry0003:AB0032,CF32134,DF34334,DD343434,DD34222
> entry0004:AB0032,CF32134
> 
> And I would like to read it into something like a hash, so that I can
> then loop over it by keys and values.
> 
> I wonder which would be the best way to do that in R?
> 
> Thanks,
> 
>     Albert.
> 
> ______________________________________________
> R-help at 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
> 
>




More information about the R-help mailing list