Hi i have the data in the following format: rent,100,1,common,674 pipe,200,0,usual,864 car,300,1,uncommon,392:jump,700,0,common,664 car,200,1,uncommon,864:snap,900,1,usual,746 stint,600,1,uncommon,257 pull,800,0,usual,594 where as i want the above 6 lines data into 8 lines as below (Spliting row 3 & 4 at : and sending to a new row): rent,100,1,common,674 pipe,200,0,usual,864 car,300,1,uncommon,392 jump,700,0,common,664 car,200,1,uncommon,864 snap,900,1,usual,746 stint,600,1,uncommon,257 pull,800,0,usual,594 Request any one who can help me getting this done. Regards, Madana -- View this message in context: http://r.789695.n4.nabble.com/Splitting-one-column-value-into-multiple-rows-tp3668835p3668835.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
On Jul 14, 2011, at 6:47 PM, Madana_Babu wrote:> Hi i have the data in the following format: > > rent,100,1,common,674 > pipe,200,0,usual,864 > car,300,1,uncommon,392:jump,700,0,common,664 > car,200,1,uncommon,864:snap,900,1,usual,746 > stint,600,1,uncommon,257 > pull,800,0,usual,594 > > where as i want the above 6 lines data into 8 lines as below > (Spliting row 3 > & 4 at : and sending to a new row):> Lines <- readLines(textConnection("rent,100,1,common,674 + pipe,200,0,usual,864 + car,300,1,uncommon,392:jump,700,0,common,664 + car,200,1,uncommon,864:snap,900,1,usual,746 + stint,600,1,uncommon,257 + pull,800,0,usual,594")) > closeAllConnections() > newlines <- strsplit(Lines, ":") > newlines2 <- unlist(newlines) > newlines2 [1] "rent,100,1,common,674" "pipe,200,0,usual,864" "car, 300,1,uncommon,392" "jump,700,0,common,664" [5] "car,200,1,uncommon,864" "snap,900,1,usual,746" "stint, 600,1,uncommon,257" "pull,800,0,usual,594" > read.table(textConnection(newlines2), sep=",") V1 V2 V3 V4 V5 1 rent 100 1 common 674 2 pipe 200 0 usual 864 3 car 300 1 uncommon 392 4 jump 700 0 common 664 5 car 200 1 uncommon 864 6 snap 900 1 usual 746 7 stint 600 1 uncommon 257 8 pull 800 0 usual 594> > rent,100,1,common,674 > pipe,200,0,usual,864 > car,300,1,uncommon,392 > jump,700,0,common,664 > car,200,1,uncommon,864 > snap,900,1,usual,746 > stint,600,1,uncommon,257 > pull,800,0,usual,594 > > Request any one who can help me getting this done. > > Regards, > Madana > > -- > View this message in context: http://r.789695.n4.nabble.com/Splitting-one-column-value-into-multiple-rows-tp3668835p3668835.html > Sent from the R help mailing list archive at Nabble.com. > [[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.David Winsemius, MD West Hartford, CT
Hi, This is working with when i have few lines and when i give those input lines in R window. But i want to apply this function on a variable which is a part of dataset and the data set is very large in size. Any help in this aspect will really help me a lot. Regards, Madana -- View this message in context: http://r.789695.n4.nabble.com/Splitting-one-column-value-into-multiple-rows-tp3668835p3671087.html Sent from the R help mailing list archive at Nabble.com.
On Jul 15, 2011, at 6:05 PM, Madana_Babu wrote:> Hi, > > This is working with when i have few lines and when i give those > input lines > in R window. But i want to apply this function on a variable which > is a part > of dataset and the data set is very large in size. Any help in this > aspect > will really help me a lot.Define "very large". And provide machine specifics and the full text of any errors you are encountering. There is no reason you cannot offer a column of an R data.frame to teh textConnection function. It will behave exactly like a file. -- David Winsemius, MD West Hartford, CT
Hi David, PFB the details of my query. Request your help in getting this resolved. # TESTING is my dataset with almost 40K rows. I am importing this dataset from my local desktop TESTING <- read.table("/Users/madana/Desktop/testing.txt", header=FALSE, sep="\t", na.strings="", dec=".", strip.white=TRUE) TESTING # I tried the following two ways. Let me know if i am using right syntax. Lines <- readLines(textConnection(data.frame(TESTING$V1))) # Error message is: Error in textConnection(data.frame(TESTING$V1)) : invalid 'text' argument Lines <- readLines(textConnection(data.frame("TESTING", header=FALSE, sep="\t", na.strings="", dec=".", strip.white=TRUE))) # Error message is: Error in textConnection(data.frame("TESTING", header = FALSE, sep = "\t", : argument 'object' must deparse to a single character string closeAllConnections() newlines <- strsplit(Lines, ":") # Error message is: Error in strsplit(Lines, ":") : non-character argument newlines2 <- unlist(newlines) cleaned_data <- read.table(textConnection(newlines2), sep=",") # Error message is: Error in textConnection(newlines2) : invalid 'text' argument My machine Config is: Dual Core. Thanks & Regards, Madana -- View this message in context: http://r.789695.n4.nabble.com/Splitting-one-column-value-into-multiple-rows-tp3668835p3674386.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
Peter Dalgaard-2 wrote:> > On Jul 18, 2011, at 06:09 , David Winsemius wrote: > >>>> PFB >> >> What ever that TLA means .... > > Just google for it: Postcard from Buster.... ;-) ><offtopic> I did and found this gem for PFB Pseudofolliculitis barbae, a medical term for persistent inflammation caused by shaving </offtopic> Berend -- View this message in context: http://r.789695.n4.nabble.com/Splitting-one-column-value-into-multiple-rows-tp3668835p3674945.html Sent from the R help mailing list archive at Nabble.com.