[R] Efficient way to parse string and construct data.frame
Gabor Grothendieck
ggrothendieck at gmail.com
Tue Aug 28 18:51:29 CEST 2007
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, yoooooo <magno_yu at ml.com> 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 2 3
> 2 4 5 6
>
> 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 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
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list