[R] size limit of string/parse a string and convert to vector

jim holtman jholtman at gmail.com
Mon Sep 6 15:24:27 CEST 2010


try this:

> x <- "|1,ab,2.34|2,cd,3.44|"
> # split by the "|" and remove vectors of zero characters
> x.sp <- strsplit(x, '|', fixed = TRUE)[[1]]
> x.sp <- x.sp[nchar(x.sp) > 0]
> # now split by comma
> x.comma <- strsplit(x.sp, ',')
> # you can now access you data
> x.comma
[[1]]
[1] "1"    "ab"   "2.34"

[[2]]
[1] "2"    "cd"   "3.44"



On Mon, Sep 6, 2010 at 6:06 AM, rajeshj at cse.iitm.ac.in
<rajeshj at cse.iitm.ac.in> wrote:
>
> Hi,
> I have a loop as follows,
>
> dataStr <- character(0)
>  repeat{
>  fstr<-read.socket(sockfd)
>  if(fstr=="")
>  break
>  dataStr<-paste(dataStr,fstr)
>  }
>
> at what point does dataStr stop accepting(gets full)? I'm sending millions of records over the socket and need to know if all of it can go into dataStr.
>
> Also, Incase all of it cannot go into dataStr, I need to parse each read.socket. In such a case,
> I have a string as follows,
> "|1,ab,2.34|2,cd,3.44|" how can I parse this to become a list of 2 string vectors, namely,
> list(c("1","ab","2.34"),c("2","cd","3.44"))
>
> Any help is appreciated
>        [[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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



More information about the R-help mailing list