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

2011-06-23 Thread Michael Pearmain
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@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.


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

2011-06-23 Thread Uwe Ligges



On 23.06.2011 16:39, Michael Pearmain 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



I don't understand why you want 40 empty list elements, but here is what 
you asked for (not optimized, just hacked in few seconds):


temp - strsplit(d, :)
num - as.numeric(sapply(temp, [[, 1))
L - vector(mode = list, length = max(num))
for(i in seq_along(temp)){
L[[num[i]]] - as.numeric(unlist(strsplit(temp[[i]][2], ,)))
}
L

Uwe Ligges




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@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.


__
R-help@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.


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

2011-06-23 Thread Henrique Dallazuanna
l - readLines(textConnection(1: 3,4,5,6
2:1,2,3
43: 5,7,8,9,5))

On Thu, Jun 23, 2011 at 12:28 PM, Henrique Dallazuanna www...@gmail.com wrote:
 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.pearm...@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@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




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

__
R-help@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.


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

2011-06-23 Thread Michael Pearmain
Thanks Uwe,

The list elements was a mistake on my part, i just wanted everything before
the : to be the name of the element.
Thanks for the help, i can play around with this to get what i want.

M


2011/6/23 Uwe Ligges lig...@statistik.tu-dortmund.de



 On 23.06.2011 16:39, Michael Pearmain 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



 I don't understand why you want 40 empty list elements, but here is what
 you asked for (not optimized, just hacked in few seconds):

 temp - strsplit(d, :)
 num - as.numeric(sapply(temp, [[, 1))
 L - vector(mode = list, length = max(num))
 for(i in seq_along(temp)){
L[[num[i]]] - as.numeric(unlist(strsplit(**temp[[i]][2], ,)))
 }
 L

 Uwe Ligges



  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@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



[[alternative HTML version deleted]]

__
R-help@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.


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

2011-06-23 Thread Henrique Dallazuanna
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.pearm...@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@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

__
R-help@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.


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

2011-06-23 Thread David Winsemius


On Jun 23, 2011, at 11:19 AM, Uwe Ligges wrote:




On 23.06.2011 16:39, Michael Pearmain 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



I don't understand why you want 40 empty list elements, but here is  
what you asked for (not optimized, just hacked in few seconds):


temp - strsplit(d, :)
num - as.numeric(sapply(temp, [[, 1))
L - vector(mode = list, length = max(num))
for(i in seq_along(temp)){
   L[[num[i]]] - as.numeric(unlist(strsplit(temp[[i]][2], ,)))
}
L


I wondered about that too. Perhaps he would be satisfied with alpha  
indexing:


d - c( 1: 3,4,5,6, 2:1,2,3, 43: 5,7,8,9,5)
 temp - strsplit(d, :)
 num - sapply(temp, [[, 1)
 L - vector(mode = list)
 for(i in seq_along(temp)){
L[[num[i]]] - as.numeric(unlist(strsplit(temp[[i]][2], ,)))
 }

 L
$`1`
[1] 3 4 5 6

$`2`
[1] 1 2 3

$`43`
[1] 5 7 8 9 5



Uwe Ligges



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




David Winsemius, MD
West Hartford, CT

__
R-help@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.


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

2011-06-23 Thread Michael Pearmain
Thanks All,

Henrique, gave me the solution is was looking for, the indexing was a
mistake on my part.

Thanks again

On 23 June 2011 16:37, David Winsemius dwinsem...@comcast.net wrote:


 On Jun 23, 2011, at 11:19 AM, Uwe Ligges wrote:



 On 23.06.2011 16:39, Michael Pearmain 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



 I don't understand why you want 40 empty list elements, but here is what
 you asked for (not optimized, just hacked in few seconds):

 temp - strsplit(d, :)
 num - as.numeric(sapply(temp, [[, 1))
 L - vector(mode = list, length = max(num))
 for(i in seq_along(temp)){
   L[[num[i]]] - as.numeric(unlist(strsplit(**temp[[i]][2], ,)))
 }
 L


 I wondered about that too. Perhaps he would be satisfied with alpha
 indexing:

 d - c( 1: 3,4,5,6, 2:1,2,3, 43: 5,7,8,9,5)
  temp - strsplit(d, :)
  num - sapply(temp, [[, 1)
  L - vector(mode = list)

  for(i in seq_along(temp)){
L[[num[i]]] - as.numeric(unlist(strsplit(**temp[[i]][2], ,)))
  }

  L
 $`1`

 [1] 3 4 5 6

 $`2`
 [1] 1 2 3

 $`43`
 [1] 5 7 8 9 5


  Uwe Ligges



  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




 David Winsemius, MD
 West Hartford, CT



[[alternative HTML version deleted]]

__
R-help@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.