Hi, Just a modification: x1<-gsub("[$]"," ",x) read.table(text=x1,sep="",header=FALSE,stringsAsFactors=FALSE) # V1 V2 V3 #1 qwer 12 qwre #2 ewrtr 7789 ewwe A.K.
----- Original Message ----- From: David L Carlson <dcarl...@tamu.edu> To: 'Bert Gunter' <gunter.ber...@gene.com>; 'Sarah Goslee' <sarah.gos...@gmail.com> Cc: 'r-help' <r-help@r-project.org> Sent: Monday, November 26, 2012 2:33 PM Subject: Re: [R] Help in splitting the records Another approach is to use gsub() followed by read.table(): > x <- c("qwer$$12$$qwre", "ewrtr$7789$ewwe") > x <- gsub("\\$+", "\\$", x) > x <- read.table(text=x, sep="$", stringsAsFactors=FALSE) > x V1 V2 V3 1 qwer 12 qwre 2 ewrtr 7789 ewwe ---------------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77843-4352 > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Bert Gunter > Sent: Monday, November 26, 2012 1:00 PM > To: Sarah Goslee > Cc: r-help > Subject: Re: [R] Help in splitting the records > > Sarah: > > You may not agree, but the following avoids the IMHO ugly rbind() and > separate conversion to numeric by using scan(): > > ## first, as before.. > > x <- c("qwer$$12$$qwre", "ewrtr$7789$ewwe") > x <- strsplit(x, "\\$+") > > ## Then, instead ... > > x.convert <- > data.frame(scan(textConnection(unlist(x)),wh=list("a",0,"a"))) > > ## You'll need to replace with suitable column names, of course > > Cheers, > Bert > > > On Mon, Nov 26, 2012 at 9:00 AM, Sarah Goslee > <sarah.gos...@gmail.com>wrote: > > > You state that you want "$$$" as the separator, but your example has > > "$$" and "$" so I'm assuming an indeterminate number of consecutive > > $. > > > > x <- c("qwer$$12$$qwre", "ewrtr$7789$ewwe") > > x <- strsplit(x, "\\$+") > > x <- do.call(rbind, x) > > x <- data.frame(x, stringsAsFactors = FALSE) > > x$X2 <- as.numeric(x$X2) > > > > I've also made some assumptions about what you want the output to be > > like, since you didn't specify, and broken it into as many steps as > > possible so that you can look at what functions I used and read the > > help files. > > > > Sarah > > > > On Mon, Nov 26, 2012 at 5:51 AM, arunkumar1111 <akpbond...@gmail.com> > > wrote: > > > Hi > > > > > > I have set of records seperated by a separator say "$$$" i want to > get > > the > > > values in a dataframe. > > > > > > eq > > > > > > qwer$$12$$qwre > > > ewrtr$7789$ewwe > > > > > > I want the output as\ > > > > > > V1 V2 V3 > > > qwer 12 qwre > > > ewrtr 7789 ewwwe > > > > > > > > > > > > Please help me > > > > > > > > > > > > -- > > Sarah Goslee > > http://www.functionaldiversity.org > > > > ______________________________________________ > > 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. > > > > > > -- > > Bert Gunter > Genentech Nonclinical Biostatistics > > Internal Contact Info: > Phone: 467-7374 > Website: > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb- > biostatistics/pdb-ncb-home.htm > > [[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. ______________________________________________ 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.