[R] Loading List data into R with scan()

Henrique Dallazuanna wwwhsd at gmail.com
Thu Jun 23 17:28:09 CEST 2011


Try this:

 sapply(lapply(strsplit(l, ":"), strsplit, ","),
function(x)structure(lapply(x[2], as.numeric), .Names = x[1]))

On Thu, Jun 23, 2011 at 11:39 AM, Michael Pearmain
<michael.pearmain at gmail.com> wrote:
> Hi All,
>
> I've been given a data file of the form:
> 1: 3,4,5,6
> 2:1,2,3
> 43: 5,7,8,9,5
>
> and i want to read this data in as a list to create the form:
> (guessing final look)
> my.list
> [[1]]
> [1] 3 4 5 6
>
> [[2]]
> [1] 1 2 3
>
> [[43]]
> [1] 5 7 8 9 5
>
> I can get to a stage using scan:
> scan("my.data", what = character(0), quiet = TRUE)
> to load
> [1] "1: 3,4,5,6"
> [2] "2:1,2,3"
> [3] "43: 5,7,8,9,5"
>
> but im not sure on how next to proceed to arrange this into a list form, can
> anyone offer some advise?
>
> Thanks in advance
>
> Mike
>
>        [[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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list