Re: [R] Data frame organization
Aaaah finally !!! Thanks a lot !!! Arnaud Le lun. 26 août 2019 18 h 28, Jim Lemon a écrit : > Hi Arnaud, > The reason I wrote the following function is that it always takes me > half a dozen tries with "reshape" before I get the syntax right: > > amdf<-read.table(text="A 10 > B 5 > C 9 > A 5 > B 15 > C 20") > library(prettyR) > stretch_df(amdf,"V1","V2") > V1 V2_1 V2_2 > 1 A 105 > 2 B5 15 > 3 C9 20 > > Jim > > On Tue, Aug 27, 2019 at 4:06 AM Arnaud Mosnier > wrote: > > > > Hi, > > > > I have a really simple question. > > I need to convert a data.frame with the following format > > > > A 10 > > B 5 > > C 9 > > A 5 > > B 15 > > C 20 > > > > in this format > > > > A 10 5 > > B 515 > > C 920 > > > > Thanks !!! > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Data frame organization
Hi Arnaud, The reason I wrote the following function is that it always takes me half a dozen tries with "reshape" before I get the syntax right: amdf<-read.table(text="A 10 B 5 C 9 A 5 B 15 C 20") library(prettyR) stretch_df(amdf,"V1","V2") V1 V2_1 V2_2 1 A 105 2 B5 15 3 C9 20 Jim On Tue, Aug 27, 2019 at 4:06 AM Arnaud Mosnier wrote: > > Hi, > > I have a really simple question. > I need to convert a data.frame with the following format > > A 10 > B 5 > C 9 > A 5 > B 15 > C 20 > > in this format > > A 10 5 > B 515 > C 920 > > Thanks !!! > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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 -- To UNSUBSCRIBE and more, see 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] Data Frame Organization
There is some issue with the plain text vs. HTML - please find the answer again. If illegible kindly see the attached pic. Best Wishes. s. x <- c('A', 'B', 'C', 'A', 'B', 'C') y <- c(10, 5, 9, 5, 15, 20) df <- data.frame(x,y) df f <- reshape(df, v.names = "y", idvar = "x", timevar = "y", direction = "wide") RESULT: > f x y.10 y.5 y.9 y.15 y.201 A 10 5 NA NA NA2 B NA 5 NA 15 NA3 C NA NA 9 NA 20 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Data frame organization
Dear Arnaud, I just played around with your data a bit and found this to be useful. But kindly note that I am NO expert like the other people in the group. My answer to you is purely for help purposes. My knowledge in R too is limited. I used the reshape function and arrived at something. I am sure others will arrive at a better and more crisp answer that I have. Again please note: I am only a novice. x <- c('A', 'B', 'C', 'A', 'B', 'C')y <- c(10, 5, 9, 5, 15, 20)df <- data.frame(x,y)dff <- reshape(df, v.names = "y", idvar = "x", timevar = "y", direction = "wide") RESULT: > f x y.10 y.5 y.9 y.15 y.201 A 10 5 NA NA NA2 B NA 5 NA 15 > NA3 C NA NA 9 NA 20 Hope this is of any use. Kind Regards, s. On Monday, 26 August 2019, 11:37:13 pm GMT+5:30, Arnaud Mosnier wrote: Hi, I have a really simple question. I need to convert a data.frame with the following format A 10 B 5 C 9 A 5 B 15 C 20 in this format A 10 5 B 5 15 C 9 20 Thanks !!! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Data frame organization
Hi, I have a really simple question. I need to convert a data.frame with the following format A 10 B 5 C 9 A 5 B 15 C 20 in this format A 10 5 B 515 C 920 Thanks !!! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.