Re: [R] Help with reshape/reshape2 needed

2017-07-05 Thread Jim Lemon
Oops, that should have been: stretch_df(tadf,"V1","V2") Jim On Thu, Jul 6, 2017 at 8:38 AM, Jim Lemon wrote: > Hi Tom, > Or perhaps: > > #assume the data frame is named "tadf" > library(prettyR) > stretch_df(tadf,1,2) > > Jim > > > On Thu, Jul 6, 2017 at 6:50 AM, Ista Zahn wrote: >> The reason

Re: [R] Help with reshape/reshape2 needed

2017-07-05 Thread Jim Lemon
Hi Tom, Or perhaps: #assume the data frame is named "tadf" library(prettyR) stretch_df(tadf,1,2) Jim On Thu, Jul 6, 2017 at 6:50 AM, Ista Zahn wrote: > The reason it doesn't work easily with reshape/reshape2 is that the > order of the rows is not determined. Your answer could be > > 1957

Re: [R] Help with reshape/reshape2 needed

2017-07-05 Thread Ista Zahn
The reason it doesn't work easily with reshape/reshape2 is that the order of the rows is not determined. Your answer could be 1957 1958 ... 1985 1986 0.8625000 0.750 ... 0.7307692 0.2375 0.0733945 0.6435644 ...NA 0.05769231 0.5096154NA ...NA 0.6

Re: [R] Help with reshape/reshape2 needed

2017-07-05 Thread Thomas Adams
David, That's just awesome! LOL -- no wonder I couldn't see how the reshape functions could do this; you saved me MANY days! Thank you so much! Best, Tom On Wed, Jul 5, 2017 at 3:48 PM, David L Carlson wrote: > This does not use reshape/reshape2, but it is pretty straightforward. > Assuming X

Re: [R] Help with reshape/reshape2 needed

2017-07-05 Thread David L Carlson
This does not use reshape/reshape2, but it is pretty straightforward. Assuming X is your example data: > Y <- split(X[, 2], X[, 1]) > vals <- sapply(Y, length) > pad <- max(vals) - vals > Y2 <- lapply(seq_along(Y), function(x) c(Y[[x]], rep(NA, pad[x]))) > names(Y2) <- names(Y) > X2 <- do.call(cb

Re: [R] help with reshape

2015-09-09 Thread Ivan Calandra
ra; R list Subject: Re: [R] help with reshape I don't think it is platform or version specific. The purpose of the missing value, NA (i.e. Not Available), is to flag the value for special handling in some way, often by deletion. You cannot assume that NA will be treated as any other value since

Re: [R] help with reshape

2015-09-08 Thread PIKAL Petr
Of David L > Carlson > Sent: Tuesday, September 08, 2015 5:03 PM > To: Ivan Calandra; R list > Subject: Re: [R] help with reshape > > I don't think it is platform or version specific. The purpose of the > missing value, NA (i.e. Not Available), is to flag the value for >

Re: [R] help with reshape

2015-09-08 Thread David L Carlson
2015 9:33 AM To: R list Subject: Re: [R] help with reshape David, It seems that your solution works, but why would that be? And why would this NA behavior be platform or version specific? I really need to check with a newer version of R... Ivan -- Ivan Calandra, PhD University of Reims Cham

Re: [R] help with reshape

2015-09-08 Thread Ivan Calandra
, TX 77840-4352 Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ivan Calandra Sent: Tuesday, September 8, 2015 7:56 AM To: PIKAL Petr; R list Subject: Re: [R] help with reshape Thanks Petr, It looks good, but I have to check in more details. Can anyone he

Re: [R] help with reshape

2015-09-08 Thread David L Carlson
pe(). - David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ivan Calandra Sent: Tuesday, September 8, 2015 7:56 AM To: PIKAL

Re: [R] help with reshape

2015-09-08 Thread Ivan Calandra
08, 2015 3:25 PM To: PIKAL Petr; R list Subject: Re: [R] help with reshape I do get only 2 lines: mydata <- structure(list(ID = c(543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 11574, 11575, 11576, 11577, 11578, 11579, 11580, 11581, 11

Re: [R] help with reshape

2015-09-08 Thread PIKAL Petr
result, though. Cheers Petr > -Original Message- > From: Ivan Calandra [mailto:ivan.calan...@univ-reims.fr] > Sent: Tuesday, September 08, 2015 3:25 PM > To: PIKAL Petr; R list > Subject: Re: [R] help with reshape > > I do get only 2 lines: > > mydata <-

Re: [R] help with reshape

2015-09-08 Thread Ivan Calandra
1667, 291.93333333, NA), Moyenne.Ca3158 = c(578.2, 278.8333, NA), Moyenne.Cd2288 = c(0.1514, 0.819, NA), Moyenne.Co2286 = c(NA_real_, NA_real_, NA_real_), Moyenne.Co2378 = c(1.87225, 3.946, NA ), Moyenne.Cr2055 = c(NA_real_, NA_real_, NA_real_), Moyenn

Re: [R] help with reshape

2015-09-08 Thread PIKAL Petr
890 = c(NA, NA, NA, 3.9615), As1937 = c(3.7455, NA, 2.2755, 3.488333), Ca1840 = c(596.1667, NA, 291.9333, 337.4333), Ca3158 = c(578.2, NA, 278.8333, 323.5333), Cd2288 = c(0.1514, NA, 0.819, 0.87716666667), Co2286 = c(NA, NA, NA, 0.2924667),

Re: [R] help with reshape

2015-09-08 Thread Ivan Calandra
ur solution as I use reshape only sparsely. Cheers Petr -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ivan Calandra Sent: Tuesday, September 08, 2015 2:18 PM To: R list Subject: Re: [R] help with reshape Thank you Petr, It kinda works, but not comple

Re: [R] help with reshape

2015-09-08 Thread PIKAL Petr
m: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ivan > Calandra > Sent: Tuesday, September 08, 2015 2:18 PM > To: R list > Subject: Re: [R] help with reshape > > Thank you Petr, > > It kinda works, but not completely. The problem is that it produces a > column

Re: [R] help with reshape

2015-09-08 Thread Ivan Calandra
Thank you Petr, It kinda works, but not completely. The problem is that it produces a column for each value ("Moyenne"), and not each element of "Elem". That means I have only one value per column, instead of up to 3. For example, I have 3 columns for Al1670 instead of just one, and each colum

Re: [R] help with reshape

2015-09-08 Thread PIKAL Petr
Hi I am not sure if I got it library(reshape2) mm<-melt(mydata, measure.vars="Moyenne") test <- dcast(mm, Etape+Ech+repet+dilution+Rincage~Elem+value) gives me 3 rows but names need some tweaking afterwards. nn<-paste("Moyenne", unlist(lapply(strsplit(names(test)[-(1:5)], "_"), "[", 1)), sep="

Re: [R] help with reshape is needed again!

2010-06-19 Thread xin wei
thank you very much for such a thorough solution! -- View this message in context: http://r.789695.n4.nabble.com/help-with-reshape-is-needed-again-tp2260640p2260943.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org

Re: [R] help with reshape is needed again!

2010-06-18 Thread Dennis Murphy
Hi: # Method 1: Transposition and name corrections > dd <- read.table(textConnection(" + gene1 breast 10100 1 + gene2 breast 20200 4 + gene3 breast 3050 5 + gene4 breast 40400 9")) > cl

Re: [R] Help with reshape/reShape and indexing

2009-05-13 Thread Dana Sevak
To all of you who answered me: Thank you so much! Each approach taught me something new and I really appreciate your help! Best regards, Dana Sevak __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the pos

Re: [R] Help with reshape/reShape and indexing

2009-05-13 Thread hadley wickham
> This does it more or less your way: > > ds <- split(df, df$Name) > ds <- lapply(ds, function(x){x$Index <- seq_along(x[,1]); x}) > df2 <- unsplit(ds, df$Name) > tapply(df2$X1, df2[,c("Name", "Index")], function(x) x) > > athough there may exist much easier ways ... Here's one way with the plyr a

Re: [R] Help with reshape/reShape and indexing

2009-05-13 Thread Gabor Grothendieck
Try this: DF$Index <- ave(1:nrow(DF), DF$Name, FUN = seq_along) reshape(DF[-3], dir = "wide", idvar = "Name", timevar = "Index") Also see the reshape package for another similar facility. On Wed, May 13, 2009 at 2:02 AM, Dana Sevak wrote: > > Dear R Helpers, > > I have trouble applying reShap

Re: [R] Help with reshape/reShape and indexing

2009-05-13 Thread Dimitris Rizopoulos
one way is the following: df.index <- df df.index$Index <- ave(seq_along(df$Name), df$Name, FUN = seq_along) df.index df2 <- reshape(df.index[c("Name", "Index", "X1")], timevar = "Index", idvar = "Name", direction = "wide") df2 I hope it helps. Best, Dimitris Dana Sevak wrote: Dear R Hel

Re: [R] Help with reshape/reShape and indexing

2009-05-13 Thread Uwe Ligges
Dana Sevak wrote: Dear R Helpers, I have trouble applying reShape and reshape although I read the documentation and several posts, so I would very much appreciate your help on the two points below. I have a dataframe df = data.frame(Name=c("a", "a", "a", "b", "b", "c"), X1=c("12", "13", "1