Re: [R] Efficient way to parse string and construct data.frame

2007-08-28 Thread Gabor Grothendieck
Try this:

> s <- c("1 ,2 ,3",  "4 ,5 ,6")
> read.csv(textConnection(s), header = FALSE)
  V1 V2 V3
1  1  2  3
2  4  5  6
>


On 8/28/07, yoo <[EMAIL PROTECTED]> wrote:
>
> Hi all,
>
> I have this list of strings
> [1] "1 ,2 ,3"  "4 ,5 ,6"
>
> Is there an efficient way to convert it to data.frame:
>   V1  V2  V3
> 1   1   23
> 2   4   56
>
> Like I can use strsplit to get to a list of split strings.. and then use say
> a = strsplit(mylist, ",")
> data.frame(V1 = lapply(a, function(x){x[1]}), V2 = lapply(a,
> function(x){x[2]}),.)
>
> but i'm loop through that list so many times.. so I'm hesitated to use
> that..
>
> Thanks a lot for your great help before and this time as well!!
> - boy
> --
> View this message in context: 
> http://www.nabble.com/Efficient-way-to-parse-string-and-construct-data.frame-tf4342441.html#a12370234
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@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
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Efficient way to parse string and construct data.frame

2007-08-28 Thread Henrique Dallazuanna
Hi,

do.call("rbind", lapply(strsplit(mylist, ","), as.numeric))

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

On 28/08/07, yoo <[EMAIL PROTECTED]> wrote:
>
>
> Hi all,
>
> I have this list of strings
> [1] "1 ,2 ,3"  "4 ,5 ,6"
>
> Is there an efficient way to convert it to data.frame:
>V1  V2  V3
> 1   1   23
> 2   4   56
>
> Like I can use strsplit to get to a list of split strings.. and then use
> say
> a = strsplit(mylist, ",")
> data.frame(V1 = lapply(a, function(x){x[1]}), V2 = lapply(a,
> function(x){x[2]}),.)
>
> but i'm loop through that list so many times.. so I'm hesitated to use
> that..
>
> Thanks a lot for your great help before and this time as well!!
> - boy
> --
> View this message in context:
> http://www.nabble.com/Efficient-way-to-parse-string-and-construct-data.frame-tf4342441.html#a12370234
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@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
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


[R] Efficient way to parse string and construct data.frame

2007-08-28 Thread yoooooo

Hi all, 

I have this list of strings
[1] "1 ,2 ,3"  "4 ,5 ,6"

Is there an efficient way to convert it to data.frame:
   V1  V2  V3
1   1   23
2   4   56

Like I can use strsplit to get to a list of split strings.. and then use say
a = strsplit(mylist, ",")
data.frame(V1 = lapply(a, function(x){x[1]}), V2 = lapply(a,
function(x){x[2]}),.)

but i'm loop through that list so many times.. so I'm hesitated to use
that.. 

Thanks a lot for your great help before and this time as well!! 
- boy
-- 
View this message in context: 
http://www.nabble.com/Efficient-way-to-parse-string-and-construct-data.frame-tf4342441.html#a12370234
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.