Re: [R] Lag variable by group
Hi Petr and other member who can use this post, Somebody gave me an answer in a private email which worked for me! The only thing I needed to do was to make first a data.table object of my data. Then the code works! library(data.table) data <- data.table(data, key = "id") data[, lag.t1:=c(NA, t1[-.N]), by=id] Thank you very much for your help Petr! I really appreciate it! Janka 2015-09-08 8:37 GMT+02:00 PIKAL Petr: > Hi > > Thanks for providing data. I did not see any response and frankly speaking > I do not use data.table so I am not sure what do you mean by lagging t1. > > I would start with ordering data. > ooo<-order(data$id, data$year) > data <- data[ooo,] > > Then you can split data according to id. > > datas<-split(data[,c(1,3)], data$id) > > dput(head(datas)) > structure(list(`28954` = structure(list(year = c(2005, 2006, > 2007, 2008), t1 = c(-1.81807494163513, -1.81807494163513, > -1.81807494163513, > -1.81807494163513)), .Names = c("year", "t1"), row.names = c(58L, > 45L, 35L, 46L), class = "data.frame"), `28955` = structure(list( > year = c(2005, 2006, 2007, 2008), t1 = c(-1.81807494163513, > -1.81807494163513, -1.81807494163513, -1.81807494163513)), .Names = > c("year", > "t1"), row.names = c(59L, 70L, 69L, 72L), class = "data.frame"), > `28956` = structure(list(year = c(2005, 2006, 2007, 2008), > t1 = c(-1.81807494163513, -1.81807494163513, -1.81807494163513, > -1.81807494163513)), .Names = c("year", "t1"), row.names = c(53L, > 66L, 74L, 51L), class = "data.frame"), `28957` = structure(list( > year = c(2005, 2006, 2007, 2008), t1 = c(-1.81807494163513, > -1.81807494163513, -1.81807494163513, -1.81807494163513 > )), .Names = c("year", "t1"), row.names = c(71L, 64L, > 54L, 24L), class = "data.frame"), `28958` = structure(list( > year = c(2005, 2006, 2007, 2008), t1 = c(-1.81807494163513, > -1.81807494163513, -1.81807494163513, -1.81807494163513 > )), .Names = c("year", "t1"), row.names = c(34L, 27L, > 1L, 31L), class = "data.frame"), `28959` = structure(list( > year = c(2005, 2006, 2007, 2008), t1 = c(-1.81807494163513, > -1.81807494163513, -1.81807494163513, -1.81807494163513 > )), .Names = c("year", "t1"), row.names = c(17L, 18L, > 30L, 44L), class = "data.frame")), .Names = c("28954", "28955", > "28956", "28957", "28958", "28959")) > > But now I am lost what result you expect. Can you explain it on this > smaller data set? > > Cheers > Petr > > > -Original Message- > > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Janka > > VANSCHOENWINKEL > > Sent: Monday, September 07, 2015 1:18 PM > > To: r-help@r-project.org > > Subject: [R] Lag variable by group > > > > Hi! > > > > I have the following dataset with the variables ID (this is a unique ID > > per farmer), year, and another variable t1. > > I now would like to have a fourth variable which is the lag value of t1 > > for each farm ID. > > > > I found a code on the internet that does exactly what I need, but it > > does not work for this dataset. Does anyone have suggestions about how > > I can make this work? > > > > Thanks a lot! > > > > Janka > > > > data<-structure(list(year = c(2007, 2005, 2008, 2006, 2005, 2007, 2006, > > 2008, 2007, 2005, 2007, 2007, 2005, 2006, 2005, 2006, 2005, 2006, 2007, > > 2007, 2005, 2008, 2007, 2008, 2005, 2005, 2006, 2008, 2007, 2007, 2008, > > 2008, 2006, 2005, 2007, 2006, 2008, 2008, 2007, 2007, 2007, 2006, 2006, > > 2008, 2006, 2008, 2008, 2008, 2006, 2007, 2008, 2007, 2005, 2007, 2008, > > 2005, 2007, 2005, 2005, 2008, 2005, 2006, 2005, 2006, 2008, 2006, 2008, > > 2006, 2007, 2006, 2005, 2008, 2006, 2007, 2008, 2006, 2006, 2006, 2005, > > 2008, 2006, 2008, 2006, 2006, 2006, 2007, 2008, 2005, 2007, 2006, 2007, > > 2008, 2006, 2008, 2005, 2007, 2005, 2007, 2006, 2006), id = c(28958L, > > 28962L, 28962L, 28965L, 28960L, 28962L, 28964L, 28970L, 28961L, 28965L, > > 78458L, 28960L, 28961L, 28961L, 28969L, 28962L, 28959L, 28959L, 58845L, > > 28965L, 28963L, 78459L, 28967L, 28957L, 28964L, 28966L, 28958L, 28960L, > > 28969L, 28959L, 28958L, 28969L, 58845L, 28958L, 28954L, 28963L, 78458L, > > 28965L, 28966L, 28963L, 28970L, 28970L, 28960L, 28959L, 28954L, 28954L, > > 58845L, 28967L, 28966L, 78459L, 28956L, 28964L, 28956L, 28957L, 28961L, > > 28970L, 28968L, 28954L, 28955L, 28968L, 28968L, 28967L, 28967L, 28957L, > > 28966L, 28956L, 28964L, 28969L, 28955L, 28955L, 28957L, 28955L, 28968L, > > 28956L, 28963L, 29004L, 58848L, 29005L, 28974L, 29005L, 28974L, 29006L, > > 28981L, 29007L, 29002L, 28980L, 29001L, 29006L, 29005L, 28989L, 28989L, > > 58846L, 28980L, 28981L, 78467L, 28990L, 28973L, 29004L, 28972L, > > 29006L), t1 = c(-1.81807494163513, -1.81807494163513, - > > 1.81807494163513, -1.81807494163513, -1.81807494163513, - > > 1.81807494163513, -1.81807494163513, -1.81807494163513, - > > 1.81807494163513, -1.81807494163513, -1.81807494163513,
Re: [R] Help
Please avoid Nabble For starters, your mail has lost the original poster and all context. Anyways, (A) in this particular case it wouldn't be the sum(x issue since it would stop with a syntax error: > sum(x + 1 Error: unexpected numeric constant in: "sum(x 1" > More commonly, miscounting quote characters (' or ") is the culprit, or maybe a curly brace {. The latter would stop at any syntax error, though: > { + 1 + q() + a b Error: unexpected symbol in: "q() a b" With quotes it will go on until a matching quote is found, since character constants can be multi-line. (B) More importantly, ESC is not invariably the ticket out. It is the case in the Mac GUI and in RStudio, and presumably in RGui on Windows too, but in a Terminal application on OSX or Linux, it is Ctrl-C. -pd On 07 Sep 2015, at 17:40 , Dan Dwrote: > press ESC. > > You may have entered a command that was missing a parenthesis or something > else that R needs before it can make sense out of your code (e.g., entering > "sum(X" without the closing paren will give you that pattern). ESC brings > back the command line and you can try again. > > -Dan > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Help-tp4711952p4711960.html > Sent from the R help mailing list archive at Nabble.com. > > __ > 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. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd@cbs.dk Priv: pda...@gmail.com __ 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] Lag variable by group
Wow! Thanks for pointing that out! And thanks for testing it out as well! It is always the first year available (unbalanced panel) that should get NA. So using the code line you provided earlier, this should work: library(data.table) data <- data.table(newdata, key = "id") ooo<-order(data$id, data$year) data <- data[ooo,] data$lagvar<-data[, lag.t1:=c(NA, t1[-.N]), by=id] Thank you very much for pointing that out! 2015-09-08 9:05 GMT+02:00 PIKAL Petr: > Hm. I tried your example but what puzzles me is that your data are not > sorted by year and therefore sometimes the first year is changed to NA but > sometimes any arbitrary year is changed to NA. > > > > > head(data) > >yearidt1lag.t1 > > 1: 2007 28954 -1.818075NA > > 2: 2006 28954 -1.818075 -1.818075 > > 3: 2008 28954 -1.818075 -1.818075 > > 4: 2005 28954 -1.818075 -1.818075 > > 5: 2005 28955 -1.818075NA > > 6: 2007 28955 -1.818075 -1.818075 > > > > Is it what you intended? > > Cheers > > Petr > > > > > > *From:* Janka VANSCHOENWINKEL [mailto:janka.vanschoenwin...@uhasselt.be] > *Sent:* Tuesday, September 08, 2015 8:48 AM > *To:* PIKAL Petr > *Cc:* r-help@r-project.org > *Subject:* Re: [R] Lag variable by group > > > > Hi Petr and other member who can use this post, > > > > Somebody gave me an answer in a private email which worked for me! > > > > The only thing I needed to do was to make first a data.table object of my > data. Then the code works! > > > > library(data.table) > data <- data.table(data, key = "id") > data[, lag.t1:=c(NA, t1[-.N]), by=id] > > > > Thank you very much for your help Petr! > > > > I really appreciate it! > > > > Janka > > > > > > > > 2015-09-08 8:37 GMT+02:00 PIKAL Petr : > > Hi > > Thanks for providing data. I did not see any response and frankly speaking > I do not use data.table so I am not sure what do you mean by lagging t1. > > I would start with ordering data. > ooo<-order(data$id, data$year) > data <- data[ooo,] > > Then you can split data according to id. > > datas<-split(data[,c(1,3)], data$id) > > dput(head(datas)) > structure(list(`28954` = structure(list(year = c(2005, 2006, > 2007, 2008), t1 = c(-1.81807494163513, -1.81807494163513, > -1.81807494163513, > -1.81807494163513)), .Names = c("year", "t1"), row.names = c(58L, > 45L, 35L, 46L), class = "data.frame"), `28955` = structure(list( > year = c(2005, 2006, 2007, 2008), t1 = c(-1.81807494163513, > -1.81807494163513, -1.81807494163513, -1.81807494163513)), .Names = > c("year", > "t1"), row.names = c(59L, 70L, 69L, 72L), class = "data.frame"), > `28956` = structure(list(year = c(2005, 2006, 2007, 2008), > t1 = c(-1.81807494163513, -1.81807494163513, -1.81807494163513, > -1.81807494163513)), .Names = c("year", "t1"), row.names = c(53L, > 66L, 74L, 51L), class = "data.frame"), `28957` = structure(list( > year = c(2005, 2006, 2007, 2008), t1 = c(-1.81807494163513, > -1.81807494163513, -1.81807494163513, -1.81807494163513 > )), .Names = c("year", "t1"), row.names = c(71L, 64L, > 54L, 24L), class = "data.frame"), `28958` = structure(list( > year = c(2005, 2006, 2007, 2008), t1 = c(-1.81807494163513, > -1.81807494163513, -1.81807494163513, -1.81807494163513 > )), .Names = c("year", "t1"), row.names = c(34L, 27L, > 1L, 31L), class = "data.frame"), `28959` = structure(list( > year = c(2005, 2006, 2007, 2008), t1 = c(-1.81807494163513, > -1.81807494163513, -1.81807494163513, -1.81807494163513 > )), .Names = c("year", "t1"), row.names = c(17L, 18L, > 30L, 44L), class = "data.frame")), .Names = c("28954", "28955", > "28956", "28957", "28958", "28959")) > > But now I am lost what result you expect. Can you explain it on this > smaller data set? > > Cheers > Petr > > > > -Original Message- > > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Janka > > VANSCHOENWINKEL > > Sent: Monday, September 07, 2015 1:18 PM > > To: r-help@r-project.org > > Subject: [R] Lag variable by group > > > > Hi! > > > > I have the following dataset with the variables ID (this is a unique ID > > per farmer), year, and another variable t1. > > I now would like to have a fourth variable which is the lag value of t1 > > for each farm ID. > > > > I found a code on the internet that does exactly what I need, but it > > does not work for this dataset. Does anyone have suggestions about how > > I can make this work? > > > > Thanks a lot! > > > > Janka > > > > data<-structure(list(year = c(2007, 2005, 2008, 2006, 2005, 2007, 2006, > > 2008, 2007, 2005, 2007, 2007, 2005, 2006, 2005, 2006, 2005, 2006, 2007, > > 2007, 2005, 2008, 2007, 2008, 2005, 2005, 2006, 2008, 2007, 2007, 2008, > > 2008, 2006, 2005, 2007, 2006, 2008, 2008, 2007, 2007, 2007, 2006, 2006, > > 2008, 2006, 2008, 2008, 2008, 2006, 2007, 2008, 2007, 2005, 2007, 2008, > > 2005, 2007, 2005, 2005, 2008, 2005, 2006, 2005,
Re: [R] Lag variable by group
Hi Thanks for providing data. I did not see any response and frankly speaking I do not use data.table so I am not sure what do you mean by lagging t1. I would start with ordering data. ooo<-order(data$id, data$year) data <- data[ooo,] Then you can split data according to id. datas<-split(data[,c(1,3)], data$id) dput(head(datas)) structure(list(`28954` = structure(list(year = c(2005, 2006, 2007, 2008), t1 = c(-1.81807494163513, -1.81807494163513, -1.81807494163513, -1.81807494163513)), .Names = c("year", "t1"), row.names = c(58L, 45L, 35L, 46L), class = "data.frame"), `28955` = structure(list( year = c(2005, 2006, 2007, 2008), t1 = c(-1.81807494163513, -1.81807494163513, -1.81807494163513, -1.81807494163513)), .Names = c("year", "t1"), row.names = c(59L, 70L, 69L, 72L), class = "data.frame"), `28956` = structure(list(year = c(2005, 2006, 2007, 2008), t1 = c(-1.81807494163513, -1.81807494163513, -1.81807494163513, -1.81807494163513)), .Names = c("year", "t1"), row.names = c(53L, 66L, 74L, 51L), class = "data.frame"), `28957` = structure(list( year = c(2005, 2006, 2007, 2008), t1 = c(-1.81807494163513, -1.81807494163513, -1.81807494163513, -1.81807494163513 )), .Names = c("year", "t1"), row.names = c(71L, 64L, 54L, 24L), class = "data.frame"), `28958` = structure(list( year = c(2005, 2006, 2007, 2008), t1 = c(-1.81807494163513, -1.81807494163513, -1.81807494163513, -1.81807494163513 )), .Names = c("year", "t1"), row.names = c(34L, 27L, 1L, 31L), class = "data.frame"), `28959` = structure(list( year = c(2005, 2006, 2007, 2008), t1 = c(-1.81807494163513, -1.81807494163513, -1.81807494163513, -1.81807494163513 )), .Names = c("year", "t1"), row.names = c(17L, 18L, 30L, 44L), class = "data.frame")), .Names = c("28954", "28955", "28956", "28957", "28958", "28959")) But now I am lost what result you expect. Can you explain it on this smaller data set? Cheers Petr > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Janka > VANSCHOENWINKEL > Sent: Monday, September 07, 2015 1:18 PM > To: r-help@r-project.org > Subject: [R] Lag variable by group > > Hi! > > I have the following dataset with the variables ID (this is a unique ID > per farmer), year, and another variable t1. > I now would like to have a fourth variable which is the lag value of t1 > for each farm ID. > > I found a code on the internet that does exactly what I need, but it > does not work for this dataset. Does anyone have suggestions about how > I can make this work? > > Thanks a lot! > > Janka > > data<-structure(list(year = c(2007, 2005, 2008, 2006, 2005, 2007, 2006, > 2008, 2007, 2005, 2007, 2007, 2005, 2006, 2005, 2006, 2005, 2006, 2007, > 2007, 2005, 2008, 2007, 2008, 2005, 2005, 2006, 2008, 2007, 2007, 2008, > 2008, 2006, 2005, 2007, 2006, 2008, 2008, 2007, 2007, 2007, 2006, 2006, > 2008, 2006, 2008, 2008, 2008, 2006, 2007, 2008, 2007, 2005, 2007, 2008, > 2005, 2007, 2005, 2005, 2008, 2005, 2006, 2005, 2006, 2008, 2006, 2008, > 2006, 2007, 2006, 2005, 2008, 2006, 2007, 2008, 2006, 2006, 2006, 2005, > 2008, 2006, 2008, 2006, 2006, 2006, 2007, 2008, 2005, 2007, 2006, 2007, > 2008, 2006, 2008, 2005, 2007, 2005, 2007, 2006, 2006), id = c(28958L, > 28962L, 28962L, 28965L, 28960L, 28962L, 28964L, 28970L, 28961L, 28965L, > 78458L, 28960L, 28961L, 28961L, 28969L, 28962L, 28959L, 28959L, 58845L, > 28965L, 28963L, 78459L, 28967L, 28957L, 28964L, 28966L, 28958L, 28960L, > 28969L, 28959L, 28958L, 28969L, 58845L, 28958L, 28954L, 28963L, 78458L, > 28965L, 28966L, 28963L, 28970L, 28970L, 28960L, 28959L, 28954L, 28954L, > 58845L, 28967L, 28966L, 78459L, 28956L, 28964L, 28956L, 28957L, 28961L, > 28970L, 28968L, 28954L, 28955L, 28968L, 28968L, 28967L, 28967L, 28957L, > 28966L, 28956L, 28964L, 28969L, 28955L, 28955L, 28957L, 28955L, 28968L, > 28956L, 28963L, 29004L, 58848L, 29005L, 28974L, 29005L, 28974L, 29006L, > 28981L, 29007L, 29002L, 28980L, 29001L, 29006L, 29005L, 28989L, 28989L, > 58846L, 28980L, 28981L, 78467L, 28990L, 28973L, 29004L, 28972L, > 29006L), t1 = c(-1.81807494163513, -1.81807494163513, - > 1.81807494163513, -1.81807494163513, -1.81807494163513, - > 1.81807494163513, -1.81807494163513, -1.81807494163513, - > 1.81807494163513, -1.81807494163513, -1.81807494163513, - > 1.81807494163513, -1.81807494163513, -1.81807494163513, - > 1.81807494163513, -1.81807494163513, -1.81807494163513, - > 1.81807494163513, -1.81807494163513, -1.81807494163513, - > 1.81807494163513, -1.81807494163513, -1.81807494163513, - > 1.81807494163513, -1.81807494163513, -1.81807494163513, - > 1.81807494163513, -1.81807494163513, -1.81807494163513, - > 1.81807494163513, -1.81807494163513, -1.81807494163513, - > 1.81807494163513, -1.81807494163513, -1.81807494163513, - > 1.81807494163513, -1.81807494163513, -1.81807494163513, - > 1.81807494163513, -1.81807494163513, -1.81807494163513, - > 1.81807494163513,
Re: [R] Is there a time series resampling function ?
Thanks, Sergio. Yes, resample looks promising. I'll try it out now. -- View this message in context: http://r.789695.n4.nabble.com/Is-there-a-time-series-resampling-function-tp4711907p4711987.html Sent from the R help mailing list archive at Nabble.com. __ 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 with reshape
Dear users, I'm having troubles with reshaping a data.frame from long to wide format. I copy the output of dput() at the end of the mail because it is quite long. Each row of the column "Elem" should be transposed to a new column. All variables "Etape", "Ech", "repet", "dilution", "Rincage" define the samples. Meaning that for each unique combination of these variables, I want a single row, and as many columns as elements in "Elem". So I tried: reshape(mydata, timevar="Elem", idvar=c("Etape","Ech","repet","dilution","Rincage"), direction="wide", drop=c("ID","Nom_ech")) The problem is that some columns are not used at all for defining samples. In this case, the row "S1, F10-3, NA, 1, oui" is missing, but I don't understand why. Can you help me with that? I have no idea what I am doing wrong... Thanks in advance, Ivan 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, 11582, 11583, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702), Nom_ech = c("Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100" ), Etape = c("S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1"), Ech = c("B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3" ), repet = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), dilution = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100), Rincage = c("non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "oui", "oui", "oui", "oui", "oui", "oui", "oui", "oui", "oui", "oui", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non"), Elem = c("Al1670", "As1890", "As1937", "Ca1840", "Ca3158", "Cd2288", "Co2286", "Co2378", "Cr2055", "Cr2835", "Cu2247", "Cu3247", "Fe2382", "Fe2599", "K_7664", "Mg2795", "Mg2852", "Mn2576", "Mn2605", "Ni2216", "Al1670", "As1890", "As1937", "Ca1840", "Ca3158", "Cd2288", "Co2286", "Co2378", "Cr2055", "Cr2835", "Al1670", "As1890", "As1937", "Ca1840", "Ca3158", "Cd2288", "Co2286", "Co2378", "Cr2055", "Cr2835", "Cu2247", "Cu3247", "Fe2382", "Fe2599", "K_7664", "Mg2795", "Mg2852", "Mn2576", "Mn2605", "Ni2216"), Moyenne = c(NA, NA, 3.7455, 596.1667, 578.2, 0.1514, NA, 1.87225, NA, 0.3664, 1.859, 1.967667, NA, NA, 9.295667, 13.08, 12.69, 0.26875, 0.2877, 0.2395, 5732.333, 3.9615, 3.488333, 337.4333, 323.5333, 0.8771667, 0.2924667, NA, 1.795667, NA, 106.3267, NA, 2.2755, 291.9333, 278.8333, 0.819, NA, 3.946, NA, NA, 1.477667, 1.632667, 40.44, 40.25333, 128.9, 50.11, 49.02, 37.47333, 37.775, 0.3764)), .Names = c("ID", "Nom_ech", "Etape", "Ech", "repet", "dilution", "Rincage", "Elem", "Moyenne"), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 112L, 113L, 114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L, 128L, 129L, 130L, 131L ), class = c("tbl_df", "tbl", "data.frame")) -- Ivan Calandra, PhD University of Reims Champagne-Ardenne
Re: [R] Is there a time series resampling function ?
Cheers, mate! I thought there must be some obscure way to search from within CRAN. After reading your reply I tried Googling "CRAN signal processing". Much better. (D'oh!) -- View this message in context: http://r.789695.n4.nabble.com/Is-there-a-time-series-resampling-function-tp4711907p4711986.html Sent from the R help mailing list archive at Nabble.com. __ 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] Modelling categorical variables
Hi, I am a beginner with statistics and R and have no clue on how to model my data. I have collected information on seed traps (ID) that includes the habitat type (Hab) and different measures of distances. Also I have applied a modularity analysis, so that the seeds traps are grouped into modules. My dataset is as follow: *IDHab ModuleDistEdgeMeanDist1MeanDist2MeanDist3 F48F A 21.768 24.941 6.033 27.642F50F E 35.666** 60.505 149.927 * * 48.582 F52F B** 12.243** 103.041 72.908 * *102.375N02N B **58.681** 129.59 127.344 * * 131.383 N17N B** 62.829** 72.827 ** 76.736 * *77.644 N22N B** 89.207** 78.719 ** 75.005 * * 81.176N33N A** 23.288** 35.48** 25.317 * * 36.931N40N B** 36.734** 62.234 ** 30.68 * * 61.885N47N E ** 60.443** 66.367 ** 150.892 ** 55.097 * I am looking for a way to analyze if there is any correlation between the Module classification and the other variables. My difficulties here are: 1 - is there a way to model my data where Module is the response variable (something like Module~Hab*DistEdge*MeanDist1) ? If so, which model should I use (I only have a bit of experience with glm) and which distribution? 2 - Is that a problem if I have different types of predictor variable (factor and numerical)? Any help would be greatly appreciated, -- Jessica Lavabre-Micas [[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] help with reshape
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=".") names(test)[-(1:5)]<-nn Cheers Petr > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ivan > Calandra > Sent: Tuesday, September 08, 2015 12:33 PM > To: R list > Subject: [R] help with reshape > > Dear users, > > I'm having troubles with reshaping a data.frame from long to wide > format. > I copy the output of dput() at the end of the mail because it is quite > long. > > Each row of the column "Elem" should be transposed to a new column. All > variables "Etape", "Ech", "repet", "dilution", "Rincage" define the > samples. Meaning that for each unique combination of these variables, I > want a single row, and as many columns as elements in "Elem". > > So I tried: > reshape(mydata, timevar="Elem", > idvar=c("Etape","Ech","repet","dilution","Rincage"), direction="wide", > drop=c("ID","Nom_ech")) > > The problem is that some columns are not used at all for defining > samples. In this case, the row "S1, F10-3, NA, 1, oui" is missing, but > I don't understand why. > > Can you help me with that? I have no idea what I am doing wrong... > > Thanks in advance, > Ivan > > > > 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, 11582, 11583, 683, > 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, > 698, 699, 700, 701, 702), Nom_ech = c("Step1 B2", "Step1 B2", > "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", > "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", > "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", > "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", > "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", > "R1 S1 F1 0-3", "R1 S1 F1 0-3", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) > *100", > "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", > "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", > "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", > "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", > "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", > "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100" > ), Etape = c("S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", > "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", > "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", > "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", > "S1", "S1", "S1", "S1", "S1"), Ech = c("B2", "B2", "B2", "B2", "B2", > "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", > "B2", "B2", "B2", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", > "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", > "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", > "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3" > ), repet = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1, 1, > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), dilution = c(1, > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, > 1, 1, 1, 1, 1, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, > 100, 100, 100, 100, 100, 100, 100, 100, 100), Rincage = c("non", "non", > "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", > "non", "non", "non", "non", "non", "non", "non", "non", "oui", "oui", > "oui", "oui", "oui", "oui", "oui", "oui", "oui", "oui", "non", "non", > "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", > "non", "non", "non", "non", "non", "non", "non", "non"), Elem = > c("Al1670", "As1890", "As1937", "Ca1840", "Ca3158", "Cd2288", "Co2286", > "Co2378", "Cr2055", "Cr2835", "Cu2247", "Cu3247", "Fe2382", "Fe2599", > "K_7664", "Mg2795", "Mg2852", "Mn2576", "Mn2605", "Ni2216", "Al1670", > "As1890", "As1937", "Ca1840", "Ca3158", "Cd2288", "Co2286", "Co2378", > "Cr2055", "Cr2835", "Al1670", "As1890", "As1937", "Ca1840", "Ca3158", > "Cd2288", "Co2286", "Co2378", "Cr2055", "Cr2835", "Cu2247", "Cu3247", > "Fe2382", "Fe2599", "K_7664", "Mg2795", "Mg2852", "Mn2576", "Mn2605", > "Ni2216"), Moyenne = c(NA, NA, 3.7455, 596.1667, 578.2, 0.1514, > NA, 1.87225, NA, 0.3664, 1.859, 1.967667, NA, NA, > 9.295667, 13.08, 12.69, 0.26875, 0.2877, 0.2395, > 5732.333, 3.9615, 3.488333, 337.4333, > 323.5333, 0.8771667, 0.2924667, NA, > 1.795667, NA,
Re: [R] help with reshape
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 column contains maximum one value (the others being NA). Not sure I am being clear... By the way, I don't understand why my solution did not work; what is wrong there? Thank you again! Ivan -- Ivan Calandra, PhD University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89 ivan.calan...@univ-reims.fr https://www.researchgate.net/profile/Ivan_Calandra Le 08/09/15 14:04, PIKAL Petr a écrit : 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=".") names(test)[-(1:5)]<-nn Cheers Petr -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ivan Calandra Sent: Tuesday, September 08, 2015 12:33 PM To: R list Subject: [R] help with reshape Dear users, I'm having troubles with reshaping a data.frame from long to wide format. I copy the output of dput() at the end of the mail because it is quite long. Each row of the column "Elem" should be transposed to a new column. All variables "Etape", "Ech", "repet", "dilution", "Rincage" define the samples. Meaning that for each unique combination of these variables, I want a single row, and as many columns as elements in "Elem". So I tried: reshape(mydata, timevar="Elem", idvar=c("Etape","Ech","repet","dilution","Rincage"), direction="wide", drop=c("ID","Nom_ech")) The problem is that some columns are not used at all for defining samples. In this case, the row "S1, F10-3, NA, 1, oui" is missing, but I don't understand why. Can you help me with that? I have no idea what I am doing wrong... Thanks in advance, Ivan 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, 11582, 11583, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702), Nom_ech = c("Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100" ), Etape = c("S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1"), Ech = c("B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3" ), repet = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), dilution = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100), Rincage = c("non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "oui", "oui", "oui", "oui", "oui", "oui", "oui", "oui", "oui", "oui", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non"), Elem = c("Al1670", "As1890", "As1937", "Ca1840", "Ca3158", "Cd2288", "Co2286", "Co2378", "Cr2055", "Cr2835", "Cu2247", "Cu3247", "Fe2382", "Fe2599", "K_7664", "Mg2795", "Mg2852", "Mn2576", "Mn2605", "Ni2216", "Al1670", "As1890", "As1937",
Re: [R] names in R list's
Hi Jeff, Indeed there was something about plain-text in the r-help posting guide although I can't find it there anymore. https://www.r-project.org/posting-guide.html Is it still an requirement? Jeff, thanks for you constructive contribution ;) . Glad that you know about plain text mode in e-mails, beside doing some perl programming. I forgot about both. Even the linux admin's I know use python and thunderbird or some webmail nowadays not pine and perl, but I do not much networking, so what do I know. I think the question I am asking is legitimate. The access complexity of datastructures is specified in the documentation in case of python datastructures, java collections or stl containers. I guess this information is available for name access on R-list but I just can't find it. regards On 7 September 2015 at 16:37, Jeff Newmillerwrote: > You puzzle me. Why does someone who cannot figure out how to post an email in > plain text after so many messages on this mailing list get all worried about > access time for string indexing? > > Environment objects have those properties. They do not solve all problems > though, because they are rather heavyweight... you need a lot of lookups to > pay for their overhead. R5 objects and the hash package both use them, but I > have never found three need to use them. Yes, I do program in Perl so I know > where you are coming from, but the vector-based name lookup used in R works > quite effectively for data where the number of list items is short or where I > plan to access every element as part of my data processing anyway. > --- > Jeff NewmillerThe . . Go Live... > DCN: Basics: ##.#. ##.#. Live Go... > Live: OO#.. Dead: OO#.. Playing > Research Engineer (Solar/BatteriesO.O#. #.O#. with > /Software/Embedded Controllers) .OO#. .OO#. rocks...1k > --- > Sent from my phone. Please excuse my brevity. > > On September 7, 2015 3:34:53 AM PDT, Witold E Wolski > wrote: >>What is the access time for R lists given a name of list element, is it >>linear, log, or constant? >> >>Than what are to rules for names in R-lists >> >>That reusing names is possible makes me wonder. >> >>tmp <- as.list(c(1,2,3,4)) >>names(tmp) = c("a","a","b","b") >>tmp >>tmp$a >> >> >>What I am looking for is a standard R data structure which will allow >>me >>for fast and name lookup. > -- Witold Eryk Wolski __ 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] Modelling categorical variables
Hi You probably wont get many answers because: 1 -you post in HTML (post in plain text) 2 -you provide data which are unreadable (copy output of dput(yourdata) instead) 3 -you ask statistical question which are rarely answered here (they are better suited to stackexchange list) Regarding your models nothing prevents you to test any of them - lm, glm, ... Or go through some available documents on CRAN like e.g. Using R for Data Analysis and Graphics - Introduction, Examples and Commentary” by John Maindonald (PDF, data sets and scripts are available at JM's homepage). “Practical Regression and Anova using R” by Julian Faraway (PDF, data sets and scripts are available at the book homepage). among many others to learn how to use R for modelling. Cheers Petr > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jessica > Lavabre > Sent: Tuesday, September 08, 2015 11:01 AM > To: r-help@r-project.org > Subject: [R] Modelling categorical variables > > Hi, > > I am a beginner with statistics and R and have no clue on how to model > my data. I have collected information on seed traps (ID) that includes > the habitat type (Hab) and different measures of distances. Also I have > applied a modularity analysis, so that the seeds traps are grouped into > modules. My dataset is as follow: > > > > *IDHab ModuleDistEdgeMeanDist1MeanDist2MeanDist3 > F48F A 21.768 24.941 6.033 > 27.642F50F E 35.666** 60.505 > 149.927 * > * 48.582 F52F B** 12.243** 103.041 > 72.908 * > *102.375N02N B **58.681** > 129.59 127.344 * > * 131.383 N17N B** 62.829** 72.827 ** > 76.736 * > *77.644 N22N B** 89.207** 78.719 ** > 75.005 * > * 81.176N33N A** 23.288** 35.48** > 25.317 * > * 36.931N40N B** 36.734** 62.234 ** > 30.68 * > * 61.885N47N E ** 60.443** 66.367 ** > 150.892 ** 55.097 * > > I am looking for a way to analyze if there is any correlation between > the Module classification and the other variables. My difficulties here > are: > 1 - is there a way to model my data where Module is the response > variable (something like Module~Hab*DistEdge*MeanDist1) ? If so, which > model should I use (I only have a bit of experience with glm) and which > distribution? > 2 - Is that a problem if I have different types of predictor variable > (factor and numerical)? > > Any help would be greatly appreciated, > > -- Jessica Lavabre-Micas > > [[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. Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům. Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému. Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat. Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu. V případě, že je tento e-mail součástí obchodního jednání: - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu. - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou. - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech. - odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá. This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients. If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system. If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner. The sender of this e-mail shall not be liable for any possible damage caused by modifications of the
Re: [R] help with reshape
Hi I looked into docs to reshape2 and played around a bit and by some magical feature test <- dcast(mm, Etape+Ech+repet+dilution+Rincage~Elem) probably works as you expect. I cannot comment your 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 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 > column contains maximum one value (the others being NA). > > Not sure I am being clear... > > By the way, I don't understand why my solution did not work; what is > wrong there? > > Thank you again! > Ivan > > -- > Ivan Calandra, PhD > University of Reims Champagne-Ardenne > GEGENAA - EA 3795 > CREA - 2 esplanade Roland Garros > 51100 Reims, France > +33(0)3 26 77 36 89 > ivan.calan...@univ-reims.fr > https://www.researchgate.net/profile/Ivan_Calandra > > Le 08/09/15 14:04, PIKAL Petr a écrit : > > 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=".") names(test)[-(1:5)]<-nn > > > > Cheers > > Petr > > > > > >> -Original Message- > >> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ivan > >> Calandra > >> Sent: Tuesday, September 08, 2015 12:33 PM > >> To: R list > >> Subject: [R] help with reshape > >> > >> Dear users, > >> > >> I'm having troubles with reshaping a data.frame from long to wide > >> format. > >> I copy the output of dput() at the end of the mail because it is > >> quite long. > >> > >> Each row of the column "Elem" should be transposed to a new column. > >> All variables "Etape", "Ech", "repet", "dilution", "Rincage" define > >> the samples. Meaning that for each unique combination of these > >> variables, I want a single row, and as many columns as elements in > "Elem". > >> > >> So I tried: > >> reshape(mydata, timevar="Elem", > >> idvar=c("Etape","Ech","repet","dilution","Rincage"), > >> direction="wide", > >> drop=c("ID","Nom_ech")) > >> > >> The problem is that some columns are not used at all for defining > >> samples. In this case, the row "S1, F10-3, NA, 1, oui" is missing, > >> but I don't understand why. > >> > >> Can you help me with that? I have no idea what I am doing wrong... > >> > >> Thanks in advance, > >> Ivan > >> > >> > >> > >> 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, 11582, > 11583, > >> 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, > 696, > >> 697, 698, 699, 700, 701, 702), Nom_ech = c("Step1 B2", "Step1 B2", > >> "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 > >> B2", > >> "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 > >> B2", > >> "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 > >> B2", > >> "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", > >> "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", > >> "R1 S1 F1 0-3", "R1 S1 F1 0-3", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) > >> *100", > >> "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", > >> "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", > >> "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", > >> "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", > >> "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", > >> "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100" > >> ), Etape = c("S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", > >> "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", > >> "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", > >> "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", > >> "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1"), Ech = c("B2", "B2", > >> "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", > >> "B2", "B2", "B2", "B2", "B2", "B2", "B2", "F10-3", "F10-3", "F10-3", > >> "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", > >> "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", > >> "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10- > 3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3" > >> ), repet = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, > >> NA, NA, NA, NA, NA, NA,
Re: [R] names in R list's
> On Sep 8, 2015, at 6:53 AM, Witold E Wolskiwrote: > > Hi Jeff, > > Indeed there was something about plain-text in the r-help posting > guide although I can't find it there anymore. > https://www.r-project.org/posting-guide.html > > Is it still an requirement? Witold, See the first bullet in the “Technical details of posting” section: "No HTML posting (harder to detect spam) (note that this is the default in some mail clients - you may have to turn it off). Note that chances have become relatively high for ‘HTMLified’ e-mails to be completely intercepted (without notice to the sender).” Regards, Marc Schwartz __ 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] Help with vectors!
# my last one: xtfrm( VAS) On Tue, Sep 08, 2015 at 11:55:51AM -0700, Dan D wrote: > Great! > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Help-with-vectors-tp4711801p4712023.html > Sent from the R help mailing list archive at Nabble.com. > > __ > 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.
Re: [R] Help with vectors!
Great! -- View this message in context: http://r.789695.n4.nabble.com/Help-with-vectors-tp4711801p4712023.html Sent from the R help mailing list archive at Nabble.com. __ 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] Converting a .wav file into an mp3 file in R
Hello, I know how to read in mp3 files, e.g., using tuneR. But is it possible to read in a .wav file - as below and then compress it to mp3 format? library(tuneR) mywav <- readWave("myfile.wav") Thanks a lot for any hints! -- Dimitri Liakhovitski __ 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] extracting every nth character from a string...
> rawToChar( charToRaw( str)[ c( TRUE, FALSE)]) [1] "ACEG" Regards On Sat, Sep 05, 2015 at 04:59:54PM -0400, Evan Cooch wrote: > Suppose I had the following string, which has length of integer multiple of > some value n. So, say n=2, and the example string has a length of (2x4) = 8 > characters. > > str <- "ABCDEFGH" > > What I'm trying to figure out is a simple, base-R coded way (which I > heuristically call StrSubset in the following) to extract every nth > character from the string, to generate a new string. > > So > > str <- "ABCDEFGH" > > new_str <- StrSubset(str); > > print(new_str) > > which would yield > > "ACEG" > > > Best I could come up with is something like the following, where I extract > every odd character from the string: > > StrSubset <- function(string) > { > paste(unlist(strsplit(string,""))[seq(1,nchar(string),2)],collapse="") } > > > Anything more elegant come to mind? Trying to avoid regex if possible > (harder to explain to end-users), but if that meets the 'more elegant' sniff > test, happy to consider... > > Thanks in advance... > > __ > 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.
Re: [R] extracting every nth character from a string...
charToRaw is not good here because it splits up multibyte characters: strsplit(str, "") will split str into its characters. E.g., > str <- c("ggaaaa12:\u03b3, OOmmeeggaa12:\u03A9...") > rawToChar( charToRaw( str)[ c( TRUE, FALSE)]) [1] "gamma1:³ Omega1:©." > paste(collapse="", strsplit(str,split=NULL)[[1]][(1:nchar(str))%%2==1]) [1] "gamma1:, Omega2Ω." > gsub("(.)(.)", "\\1", str) [1] "gamma1:, Omega2Ω." Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Sep 8, 2015 at 2:37 PM, Frank Schwidomwrote: > > > rawToChar( charToRaw( str)[ c( TRUE, FALSE)]) > [1] "ACEG" > > Regards > > On Sat, Sep 05, 2015 at 04:59:54PM -0400, Evan Cooch wrote: > > Suppose I had the following string, which has length of integer multiple > of > > some value n. So, say n=2, and the example string has a length of (2x4) > = 8 > > characters. > > > > str <- "ABCDEFGH" > > > > What I'm trying to figure out is a simple, base-R coded way (which I > > heuristically call StrSubset in the following) to extract every nth > > character from the string, to generate a new string. > > > > So > > > > str <- "ABCDEFGH" > > > > new_str <- StrSubset(str); > > > > print(new_str) > > > > which would yield > > > > "ACEG" > > > > > > Best I could come up with is something like the following, where I > extract > > every odd character from the string: > > > > StrSubset <- function(string) > > { > > paste(unlist(strsplit(string,""))[seq(1,nchar(string),2)],collapse="") } > > > > > > Anything more elegant come to mind? Trying to avoid regex if possible > > (harder to explain to end-users), but if that meets the 'more elegant' > sniff > > test, happy to consider... > > > > Thanks in advance... > > > > __ > > 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. > [[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] help with reshape
Thanks Petr, It looks good, but I have to check in more details. Can anyone help me with my original solution using reshape()? I'd like to understand what I did wrong. reshape(mydata, timevar="Elem", idvar=c("Etape","Ech","repet","dilution","Rincage"), direction="wide", drop=c("ID","Nom_ech")) Thank you in advance Ivan -- Ivan Calandra, PhD University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89 ivan.calan...@univ-reims.fr https://www.researchgate.net/profile/Ivan_Calandra Le 08/09/15 14:45, PIKAL Petr a écrit : Hi I looked into docs to reshape2 and played around a bit and by some magical feature test <- dcast(mm, Etape+Ech+repet+dilution+Rincage~Elem) probably works as you expect. I cannot comment your 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 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 column contains maximum one value (the others being NA). Not sure I am being clear... By the way, I don't understand why my solution did not work; what is wrong there? Thank you again! Ivan -- Ivan Calandra, PhD University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89 ivan.calan...@univ-reims.fr https://www.researchgate.net/profile/Ivan_Calandra Le 08/09/15 14:04, PIKAL Petr a écrit : 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=".") names(test)[-(1:5)]<-nn Cheers Petr -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ivan Calandra Sent: Tuesday, September 08, 2015 12:33 PM To: R list Subject: [R] help with reshape Dear users, I'm having troubles with reshaping a data.frame from long to wide format. I copy the output of dput() at the end of the mail because it is quite long. Each row of the column "Elem" should be transposed to a new column. All variables "Etape", "Ech", "repet", "dilution", "Rincage" define the samples. Meaning that for each unique combination of these variables, I want a single row, and as many columns as elements in "Elem". So I tried: reshape(mydata, timevar="Elem", idvar=c("Etape","Ech","repet","dilution","Rincage"), direction="wide", drop=c("ID","Nom_ech")) The problem is that some columns are not used at all for defining samples. In this case, the row "S1, F10-3, NA, 1, oui" is missing, but I don't understand why. Can you help me with that? I have no idea what I am doing wrong... Thanks in advance, Ivan 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, 11582, 11583, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702), Nom_ech = c("Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100" ), Etape = c("S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1"), Ech = c("B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3",
Re: [R] help with reshape
Hi based on your data I got 3 lines with similar results as I got from melt/dcast only the rows are not in the same order. > version _ platform i386-w64-mingw32 arch i386 os mingw32 system i386, mingw32 status Under development (unstable) major 3 minor 3.0 year 2015 month 06 day15 svn rev68521 language R version.string R Under development (unstable) (2015-06-15 r68521) nickname Unsuffered Consequences > > sessionInfo() R Under development (unstable) (2015-06-15 r68521) Platform: i386-w64-mingw32/i386 (32-bit) Running under: Windows XP (build 2600) Service Pack 3 locale: [1] LC_COLLATE=Czech_Czech Republic.1250 LC_CTYPE=Czech_Czech Republic.1250 LC_MONETARY=Czech_Czech Republic.1250 [4] LC_NUMERIC=C LC_TIME=Czech_Czech Republic.1250 attached base packages: [1] stats datasets utils grDevices graphics methods base other attached packages: [1] reshape2_1.4.1 lattice_0.20-31 fun_0.1 loaded via a namespace (and not attached): [1] Rcpp_0.11.6 digest_0.6.8 MASS_7.3-40 grid_3.3.0 plyr_1.8.3 nlme_3.1-120 gtable_0.1.2 magrittr_1.5 [9] scales_0.2.5 ggplot2_1.0.1stringi_0.4-1proto_0.3-10 tools_3.3.0 stringr_1.0.0munsell_0.4.2colorspace_1.2-6 > test2<-reshape(mydata, timevar="Elem", idvar=c("Etape","Ech","repet","dilution","Rincage"), direction="wide", drop=c("ID","Nom_ech")) > dput(test2) structure(list(Etape = c("S1", "S1", "S1"), Ech = c("B2", "F10-3", "F10-\n 3"), repet = c(NA, 1, 1), dilution = c(1, 100, 100), Rincage = c("non", "non", "non"), Moyenne.Al1670 = c(NA, 106.3267, NA), Moyenne.As1890 = c(NA_real_, NA_real_, NA_real_), Moyenne.As1937 = c(3.7455, 2.2755, NA), Moyenne.Ca1840 = c(596.1667, 291.9333, 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_), Moyenne.Cr2835 = c(0.3664, NA, NA), Moyenne.Cu2247 = c(1.859, 1.477667, NA), Moyenne.Cu3247 = c(1.967667, 1.632667, NA ), Moyenne.Fe2382 = c(NA, 40.44, NA), Moyenne.Fe2599 = c(NA, 40.25333, NA), Moyenne.K_7664 = c(9.295667, NA, 128.9), Moyenne.Mg2795 = c(13.08, 50.11, NA), Moyenne.Mg2852 = c(12.69, 49.02, NA), Moyenne.Mn2576 = c(0.26875, 37.47333, NA), Moyenne.Mn2605 = c(0.2877, 37.775, NA), Moyenne.Ni2216 = c(0.2395, 0.3764, NA)), .Names = c("Etape", "Ech", "repet", "dilution", "Rincage", "Moyenne.Al1670", "Moyenne.As1890", "Moyenne.As1937", "Moyenne.Ca1840", "Moyenne.Ca3158", "Moyenne.Cd2288", "Moyenne.Co2286", "Moyenne.Co2378", "Moyenne.Cr2055", "Moyenne.Cr2835", "Moyenne.Cu2247", "Moyenne.Cu3247", "Moyenne.Fe2382", "Moyenne.Fe2599", "Moyenne.K_7664", "Moyenne.Mg2795", "Moyenne.Mg2852", "Moyenne.Mn2576", "Moyenne.Mn2605", "Moyenne.Ni2216"), row.names = c(1L, 112L, 126L), class = c("tbl_df", "tbl", "data.frame"), reshapeWide = structure(list(v.names = NULL, timevar = "Elem", idvar = c("Etape", "Ech", "repet", "dilution", "Rincage"), times = c("Al1670", "As1890", "As1937", "Ca1840", "Ca3158", "Cd2288", "Co2286", "Co2378", "Cr2055", "Cr2835", "Cu2247", "Cu3247", "Fe2382", "Fe2599", "K_7664", "Mg2795", "Mg2852", "Mn2576", "Mn2605", "Ni2216"), varying = structure(c("Moyenne.Al1670", "Moyenne.As1890", "Moyenne.As1937", "Moyenne.Ca1840", "Moyenne.Ca3158", "Moyenne.Cd2288", "Moyenne.Co2286", "Moyenne.Co2378", "Moyenne.Cr2055", "Moyenne.Cr2835", "Moyenne.Cu2247", "Moyenne.Cu3247", "Moyenne.Fe2382", "Moyenne.Fe2599", "Moyenne.K_7664", "Moyenne.Mg2795", "Moyenne.Mg2852", "Moyenne.Mn2576", "Moyenne.Mn2605", "Moyenne.Ni2216"), .Dim = c(1L, 20L))), .Names = c("v.names", "timevar", "idvar", "times", "varying"))) > dput(test) structure(list(Etape = c("S1", "S1", "S1", "S1"), Ech = c("B2", "F10-\n 3", "F10-3", "F10-3"), repet = c(NA, 1, 1, NA), dilution = c(1, 100, 100, 1), Rincage = c("non", "non", "non", "oui"), Al1670 = c(NA, NA, 106.3267, 5732.333), As1890 = 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.8771667), Co2286 = c(NA, NA, NA, 0.2924667), Co2378 = c(1.87225, NA, 3.946, NA), Cr2055 = c(NA, NA, NA, 1.795667), Cr2835 = c(0.3664, NA, NA, NA), Cu2247 = c(1.859, NA, 1.477667, NA), Cu3247 = c(1.967667, NA, 1.632667, NA), Fe2382 = c(NA, NA, 40.44, NA), Fe2599 = c(NA, NA, 40.25333, NA), K_7664 = c(9.295667, 128.9, NA, NA), Mg2795 = c(13.08, NA, 50.11, NA), Mg2852 = c(12.69, NA,
Re: [R] help with reshape
Hi Well, I cannot help you any further. It can be platform or version issue. You are using Mac, I work with PC, your R version is 3.2.1 mine is 3.3.0 (devel). Wizards from R core are appropriate for answering this. You can transfer our conversation to R-sig-Mac, if people using Mac found similar issue as you. If there is R-devel for Mac you can try to install it and test your code there. If you still get the same result you can check it on different computer, maybe with some other OS. Sorry that I cannot give you any positive answer. I hope that melt/dcast code can give you desired 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 <- 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, 11582, 11583, 683, > 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, > 698, 699, 700, 701, 702), Nom_ech = c("Step1 B2", "Step1 B2", "Step1 > B2", > "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", > "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", > "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "R1 S1 F1 > 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", > "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 > F1 0-3", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) > *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", > "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 > F1 > 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 > (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) > *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) > *100", > "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100"), Etape = c("S1", "S1", > "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", > "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", > "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", > "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", > "S1"), Ech = c("B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", > "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "F10- > 3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", > "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", > "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", > "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3"), repet = c(NA, > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1, 1, 1, 1, 1, 1, 1, 1, 1, > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), dilution = c(1, 1, 1, 1, 1, 1, 1, 1, > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 100, > 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, > 100, 100, 100, 100, 100), Rincage = c("non", "non", "non", "non", > "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", > "non", "non", "non", "non", "non", "non", "oui", "oui", "oui", "oui", > "oui", "oui", "oui", "oui", "oui", "oui", "non", "non", "non", "non", > "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", > "non", "non", "non", "non", "non", "non"), Elem = c("Al1670", "As1890", > "As1937", "Ca1840", "Ca3158", "Cd2288", "Co2286", "Co2378", "Cr2055", > "Cr2835", "Cu2247", "Cu3247", "Fe2382", "Fe2599", "K_7664", "Mg2795", > "Mg2852", "Mn2576", "Mn2605", "Ni2216", "Al1670", "As1890", "As1937", > "Ca1840", "Ca3158", "Cd2288", "Co2286", "Co2378", "Cr2055", "Cr2835", > "Al1670", "As1890", "As1937", "Ca1840", "Ca3158", "Cd2288", "Co2286", > "Co2378", "Cr2055", "Cr2835", "Cu2247", "Cu3247", "Fe2382", "Fe2599", > "K_7664", "Mg2795", "Mg2852", "Mn2576", "Mn2605", "Ni2216"), Moyenne = > c(NA, NA, 3.7455, 596.1667, 578.2, 0.1514, NA, 1.87225, NA, > 0.3664, 1.859, 1.967667, NA, NA, 9.295667, 13.08, > 12.69, 0.26875, 0.2877, 0.2395, 5732.333, 3.9615, > 3.488333, 337.4333, 323.5333, > 0.8771667, 0.2924667, NA, 1.795667, NA, > 106.3267, NA, 2.2755, 291.9333, 278.8333, > 0.819, NA, 3.946, NA, NA, 1.477667, 1.632667, 40.44, > 40.25333, 128.9, 50.11, 49.02, 37.47333, 37.775, > 0.3764)), .Names = c("ID", "Nom_ech", "Etape", "Ech", "repet", > "dilution", "Rincage", "Elem", "Moyenne"), row.names = c(1L, 2L, 3L, > 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, > 19L, 20L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 112L, 113L, > 114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L, 125L, > 126L, 127L, 128L,
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, 11582, 11583, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702), Nom_ech = c("Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100"), Etape = c("S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1"), Ech = c("B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3"), repet = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), dilution = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100), Rincage = c("non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "oui", "oui", "oui", "oui", "oui", "oui", "oui", "oui", "oui", "oui", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non"), Elem = c("Al1670", "As1890", "As1937", "Ca1840", "Ca3158", "Cd2288", "Co2286", "Co2378", "Cr2055", "Cr2835", "Cu2247", "Cu3247", "Fe2382", "Fe2599", "K_7664", "Mg2795", "Mg2852", "Mn2576", "Mn2605", "Ni2216", "Al1670", "As1890", "As1937", "Ca1840", "Ca3158", "Cd2288", "Co2286", "Co2378", "Cr2055", "Cr2835", "Al1670", "As1890", "As1937", "Ca1840", "Ca3158", "Cd2288", "Co2286", "Co2378", "Cr2055", "Cr2835", "Cu2247", "Cu3247", "Fe2382", "Fe2599", "K_7664", "Mg2795", "Mg2852", "Mn2576", "Mn2605", "Ni2216"), Moyenne = c(NA, NA, 3.7455, 596.1667, 578.2, 0.1514, NA, 1.87225, NA, 0.3664, 1.859, 1.967667, NA, NA, 9.295667, 13.08, 12.69, 0.26875, 0.2877, 0.2395, 5732.333, 3.9615, 3.488333, 337.4333, 323.5333, 0.8771667, 0.2924667, NA, 1.795667, NA, 106.3267, NA, 2.2755, 291.9333, 278.8333, 0.819, NA, 3.946, NA, NA, 1.477667, 1.632667, 40.44, 40.25333, 128.9, 50.11, 49.02, 37.47333, 37.775, 0.3764)), .Names = c("ID", "Nom_ech", "Etape", "Ech", "repet", "dilution", "Rincage", "Elem", "Moyenne"), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 112L, 113L, 114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L, 128L, 129L, 130L, 131L), class = c("tbl_df", "tbl", "data.frame")) test2<-reshape(mydata, timevar="Elem", idvar=c("Etape","Ech","repet","dilution","Rincage"), direction="wide", drop=c("ID","Nom_ech")) dput(test2) structure(list(Etape = c("S1", "S1"), Ech = c("B2", "F10-3"), repet = c(NA, 1), dilution = c(1, 100), Rincage = c("non", "non"), Moyenne.Al1670 = c(NA, 106.3267), Moyenne.As1890 = c(NA_real_, NA_real_), Moyenne.As1937 = c(3.7455, 2.2755), Moyenne.Ca1840 = c(596.1667, 291.9333), Moyenne.Ca3158 = c(578.2, 278.8333), Moyenne.Cd2288 = c(0.1514, 0.819), Moyenne.Co2286 = c(NA_real_, NA_real_), Moyenne.Co2378 = c(1.87225, 3.946), Moyenne.Cr2055 = c(NA_real_, NA_real_), Moyenne.Cr2835 = c(0.3664, NA), Moyenne.Cu2247 = c(1.859, 1.477667), Moyenne.Cu3247 = c(1.967667, 1.632667), Moyenne.Fe2382 = c(NA, 40.44),
Re: [R] names in R list's
Which answers why the list strips HTML out, but the reason we should compose in plain text is so we see what our readers will see. The stripping sometimes makes the result nearly impossible to read and deters people from wading in to give an answer. In addition, some HTML editors act like word processors and do things like substitute curly quotes in place of normal quotes, which gives R fits in examples. --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On September 8, 2015 5:03:31 AM PDT, Marc Schwartz wrote: > >> On Sep 8, 2015, at 6:53 AM, Witold E Wolski >wrote: >> >> Hi Jeff, >> >> Indeed there was something about plain-text in the r-help posting >> guide although I can't find it there anymore. >> https://www.r-project.org/posting-guide.html >> >> Is it still an requirement? > > > >Witold, > >See the first bullet in the “Technical details of posting” section: > >"No HTML posting (harder to detect spam) (note that this is the default >in some mail clients - you may have to turn it off). Note that chances >have become relatively high for ‘HTMLified’ e-mails to be completely >intercepted (without notice to the sender).” > > >Regards, > >Marc Schwartz __ 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] Laplace smoothing in J48
Hi, I am using J48 classifier. I want to now after i set A as TRUE in control option of the classifier, how could i see its effect when using predict method ? Regards Priyanka Garg School of Computers & Information Sciences University Of Hyderabad [[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] help with reshape
Dear Petr, Thank you for your help. I might look into this issue later (with the latest version of R), but for now, your solution with package reshape2 works perfectly! Bests, Ivan -- Ivan Calandra, PhD University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89 ivan.calan...@univ-reims.fr https://www.researchgate.net/profile/Ivan_Calandra Le 08/09/15 15:42, PIKAL Petr a écrit : Hi Well, I cannot help you any further. It can be platform or version issue. You are using Mac, I work with PC, your R version is 3.2.1 mine is 3.3.0 (devel). Wizards from R core are appropriate for answering this. You can transfer our conversation to R-sig-Mac, if people using Mac found similar issue as you. If there is R-devel for Mac you can try to install it and test your code there. If you still get the same result you can check it on different computer, maybe with some other OS. Sorry that I cannot give you any positive answer. I hope that melt/dcast code can give you desired 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 <- 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, 11582, 11583, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702), Nom_ech = c("Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "R1 S1 F1 0-3", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100", "S1 F1 0-3 (1) *100"), Etape = c("S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1", "S1"), Ech = c("B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "B2", "F10- 3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3", "F10-3"), repet = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), dilution = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100), Rincage = c("non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "oui", "oui", "oui", "oui", "oui", "oui", "oui", "oui", "oui", "oui", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non", "non"), Elem = c("Al1670", "As1890", "As1937", "Ca1840", "Ca3158", "Cd2288", "Co2286", "Co2378", "Cr2055", "Cr2835", "Cu2247", "Cu3247", "Fe2382", "Fe2599", "K_7664", "Mg2795", "Mg2852", "Mn2576", "Mn2605", "Ni2216", "Al1670", "As1890", "As1937", "Ca1840", "Ca3158", "Cd2288", "Co2286", "Co2378", "Cr2055", "Cr2835", "Al1670", "As1890", "As1937", "Ca1840", "Ca3158", "Cd2288", "Co2286", "Co2378", "Cr2055", "Cr2835", "Cu2247", "Cu3247", "Fe2382", "Fe2599", "K_7664", "Mg2795", "Mg2852", "Mn2576", "Mn2605", "Ni2216"), Moyenne = c(NA, NA, 3.7455, 596.1667, 578.2, 0.1514, NA, 1.87225, NA, 0.3664, 1.859, 1.967667, NA, NA, 9.295667, 13.08, 12.69, 0.26875, 0.2877, 0.2395, 5732.333, 3.9615, 3.488333, 337.4333, 323.5333, 0.8771667, 0.2924667, NA, 1.795667, NA, 106.3267, NA, 2.2755, 291.9333, 278.8333, 0.819, NA, 3.946, NA, NA, 1.477667, 1.632667, 40.44, 40.25333, 128.9, 50.11, 49.02, 37.47333, 37.775, 0.3764)), .Names = c("ID", "Nom_ech",
[R] Counting number of rain
Hello R-users, I want to ask how to count the number of daily rain data. My data as below: Year Month Day Amount 1901 1 1 0 1901 1 2 3 1901 1 3 0 1901 1 4 0.5 1901 1 5 0 1901 1 6 0 1901 1 7 0.3 1901 1 8 0 1901 1 9 0 1901 1 10 0 1901 1 11 0.5 1901 1 12 1.8 1901 1 13 0 1901 1 14 0 1901 1 15 2.5 1901 1 16 0 1901 1 17 0 1901 1 18 0 1901 1 19 0 1901 1 20 0 1901 1 21 0 1901 1 22 0 1901 1 23 0 1901 1 24 0 1901 1 25 0 1901 1 26 16.5 1901 1 27 0.3 1901 1 28 0 1901 1 29 0 1901 1 30 0 1901 1 31 0 1901 2 1 0 1901 2 2 0 1901 2 3 0 1901 2 4 0 1901 2 5 0 1901 2 6 0 1901 2 7 0 1901 2 8 0.3 1901 2 9 0 1901 2 10 0 1901 2 11 0 1901 2 12 1 1901 2 13 0.3 1901 2 14 0 1901 2 15 0 1901 2 16 0 1901 2 17 0 1901 2 18 0 1901 2 19 0 1901 2 20 0 1901 2 21 0 1901 2 22 0 1901 2 23 0.3 1901 2 24 0 1901 2 25 0 1901 2 26 0.3 1901 2 27 0 1901 2 28 0 1901 3 1 0 1901 3 2 0.8 1901 3 3 2.3 1901 3 4 0 1901 3 5 0 1901 3 6 0 1901 3 7 0 1901 3 8 0 1901 3 9 0 1901 3 10 2 1901 3 11 0 1901 3 12 0 1901 3 13 0 1901 3 14 0 1901 3 15 0 1901 3 16 0 1901 3 17 0 1901 3 18 0 1901 3 19 0 1901 3 20 0 1901 3 21 0 1901 3 22 1.5 1901 3 23 1.3 1901 3 24 0 1901 3 25 0 1901 3 26 0 1901 3 27 0 1901 3 28 0.3 1901 3 29 0.3 1901 3 30 4.6 1901 3 31 0 1901 4 1 0 1901 4 2 4.6 1901 4 3 30.7 1901 4 4 0 1901 4 5 0 1901 4 6 0 1901 4 7 0 1901 4 8 0 1901 4 9 0 1901 4 10 0 1901 4 11 0 1901 4 12 0 1901 4 13 0 1901 4 14 0 1901 4 15 0.3 1901 4 16 1.3 1901 4 17 0 1901 4 18 0 1901 4 19 0.3 1901 4 20 1 1901 4 21 9.4 1901 4 22 0.5 1901 4 23 0.3 1901 4 24 0 1901 4 25 0 1901 4 26 0 1901 4 27 0 1901 4 28 0 1901 4 29 0 1901 4 30 0 1901 5 1 0 1901 5 2 0 1901 5 3 0 1901 5 4 0 1901 5 5 0 1901 5 6 0 1901 5 7 0 1901 5 8 0.5 1901 5 9 2.3 1901 5 10 0.3 1901 5 11 0 1901 5 12 0 1901 5 13 0 1901 5 14 0 1901 5 15 0 1901 5 16 0 1901 5 17 0 1901 5 18 0 1901 5 19 0 1901 5 20 0 1901 5 21 0.5 1901 5 22 0 1901 5 23 0 1901 5 24 0 1901 5 25 0 1901 5 26 4.8 1901 5 27 10.9 1901 5 28 3.6 1901 5 29 0 1901 5 30 0 1901 5 31 5.1 1901 6 1 0.5 1901 6 2 0 1901 6 3 2 1901 6 4 0 1901 6 5 10.2 1901 6 6 33.3 1901 6 7 0.3 1901 6 8 0 1901 6 9 0 1901 6 10 0.5 1901 6 11 0.5 1901 6 12 0.3 1901 6 13 2.8 1901 6 14 5.6 1901 6 15 0.3 1901 6 16 6.6 1901 6 17 14.2 1901 6 18 4.8 1901 6 19 8.4 1901 6 20 1.8 1901 6 21 1.8 1901 6 22 0.3 1901 6 23 8.6 1901 6 24 0 1901 6 25 0 1901 6 26 0 1901 6 27 0 1901 6 28 0 1901 6 29 0 1901 6 30 0 1901 7 1 0 1901 7 2 0 1901 7 3 0 1901 7 4 0 1901 7 5 1 1901 7 6 0.5 1901 7 7 0.3 1901 7 8 0.3 1901 7 9 6.1 1901 7 10 0.3 1901 7 11 1.5 1901 7 12 0 1901 7 13 1.5 1901 7 14 0.3 1901 7 15 3.3 1901 7 16 2.3 1901 7 17 0.5 1901 7 18 0 1901 7 19 0 1901 7 20 0 1901 7 21 1.8 1901 7 22 0 1901 7 23 1 1901 7 24 0.3 1901 7 25 0.3 1901 7 26 1.3 1901 7 27 17 1901 7 28 6.6 1901 7 29 6.1 1901 7 30 0.5 1901 7 31 0.3 1901 8 1 0 1901 8 2 0 1901 8 3 0 1901 8 4 0 1901 8 5 0 1901 8 6 3.3 1901 8 7 4.1 1901 8 8 0.3 1901 8 9 0 1901 8 10 0 1901 8 11 0 1901 8 12 0 1901 8 13 0 1901 8 14 0 1901 8 15 0 1901 8 16 0 1901 8 17 0.5 1901 8 18 0 1901 8 19 0 1901 8 20 0 1901 8 21 0 1901 8 22 0 1901 8 23 0.3 1901 8 24 1 1901 8 25 0 1901 8 26 0 1901 8 27 10.2 1901 8 28 1.5 1901 8 29 0.5 1901 8 30 1.3 1901 8 31 0 1901 9 1 0 1901 9 2 3 1901 9 3 1 1901 9 4 0.5 1901 9 5 0.3 1901 9 6 0 1901 9 7 0 1901 9 8 2.3 1901 9 9 0.3 1901 9 10 0 1901 9 11 0 1901 9 12 0 1901 9 13 0 1901 9 14 0 1901 9 15 0 1901 9 16 0 1901 9 17 0 1901 9 18 1.8 1901 9 19 8.1 1901 9 20 0.3 1901 9 21 5.8 1901 9 22 4.1 1901 9 23 0.3 1901 9 24 1.8 1901 9 25 0 1901 9 26 0 1901 9 27 0 1901 9 28 0 1901 9 29 1.8 1901 9 30 0.8 1901 10 1 0 1901 10 2 0 1901 10 3 0 1901 10 4 0 1901 10 5 0.3 1901 10 6 0 1901 10 7 0 1901 10 8 0 1901 10 9 0 1901 10 10 0 1901 10 11 0.3 1901 10 12 3.8 1901 10 13 0.4 1901 10 14 9 1901 10 15 2 1901 10 16 1 1901 10 17 0 1901 10 18 0 1901 10 19 0 1901 10 20 0.3 1901 10 21 0 1901 10 22 0 1901 10 23 0 1901 10 24 0 1901 10 25 0 1901 10 26 0 1901 10 27 14.5 1901 10 28 6.4 1901 10 29 0.8 1901 10 30 0 1901 10 31 0 1901 11 1 0 1901 11 2 0 1901 11 3 0 1901 11 4 0 1901 11 5 0 1901 11 6 0 1901 11 7 0 1901 11 8 0 1901 11 9 0 1901 11 10 0 1901 11 11 0 1901 11 12 5.1 1901 11 13 0.3 1901 11 14 5.8 1901 11 15 0 1901 11 16 0 1901 11 17 1 1901 11 18 0.5 1901 11 19 0 1901 11 20 0 1901 11 21 0 1901 11 22 0 1901 11 23 0 1901 11 24 0 1901 11 25 0.3 1901 11 26 0 1901 11 27 0 1901 11 28 0 1901 11 29 0 1901 11 30 3.3 1901 12 1 0 1901 12 2 0 1901 12 3 0 1901 12 4 0 1901 12 5 0 1901 12 6 0 1901 12 7 0 1901 12 8 0 1901 12 9 0 1901 12 10 0 1901 12 11 0 1901 12 12 0 1901 12 13 0 1901 12 14 0 1901 12 15 0 1901 12 16 0 1901 12 17 0 1901 12 18 0 1901 12 19 0 1901 12 20 0 1901 12 21 6.1 1901 12 22 5.6 1901 12 23 0 1901 12 24 0 1901 12 25 0 1901 12 26 0 1901 12 27 0 1901 12 28 0 1901 12 29 0 1901 12 30 0 1901 12 31 9.9 1902 1 1 0 1902 1 2 0 1902 1 3 0 1902 1 4 4.1 1902 1 5 0 1902 1 6 0 1902 1 7 0 1902 1 8 0 1902 1 9 2.5 1902 1 10 0 1902 1 11 0 1902 1 12 0 1902 1 13 0.3 1902 1 14 0 1902 1 15 0 1902 1 16 0 1902 1 17 0 1902 1 18 0
Re: [R] help with reshape
I have not followed this thread closely, but this seems to work: mydata$repet[is.na(mydata$repet)] <- 0 reshape(mydata, timevar="Elem", idvar=c("Etape","Ech", "repet", "dilution","Rincage"), direction="wide", drop=c("ID","Nom_ech")) If this is the expected outcome, the problem is the NA values in repet. I changed them to 0 since you did not have any 0 entries in the data (otherwise you could use 999 or some other value that does not occur in the data). Change them back after running reshape(). - David L Carlson Department of Anthropology Texas A 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 Petr; R list Subject: Re: [R] help with reshape Thanks Petr, It looks good, but I have to check in more details. Can anyone help me with my original solution using reshape()? I'd like to understand what I did wrong. reshape(mydata, timevar="Elem", idvar=c("Etape","Ech","repet","dilution","Rincage"), direction="wide", drop=c("ID","Nom_ech")) Thank you in advance Ivan -- Ivan Calandra, PhD University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89 ivan.calan...@univ-reims.fr https://www.researchgate.net/profile/Ivan_Calandra Le 08/09/15 14:45, PIKAL Petr a écrit : > Hi > > I looked into docs to reshape2 and played around a bit and by some magical > feature > > test <- dcast(mm, Etape+Ech+repet+dilution+Rincage~Elem) > > probably works as you expect. > > I cannot comment your 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 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 >> column contains maximum one value (the others being NA). >> >> Not sure I am being clear... >> >> By the way, I don't understand why my solution did not work; what is >> wrong there? >> >> Thank you again! >> Ivan >> >> -- >> Ivan Calandra, PhD >> University of Reims Champagne-Ardenne >> GEGENAA - EA 3795 >> CREA - 2 esplanade Roland Garros >> 51100 Reims, France >> +33(0)3 26 77 36 89 >> ivan.calan...@univ-reims.fr >> https://www.researchgate.net/profile/Ivan_Calandra >> >> Le 08/09/15 14:04, PIKAL Petr a écrit : >>> 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=".") names(test)[-(1:5)]<-nn >>> >>> Cheers >>> Petr >>> >>> -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ivan Calandra Sent: Tuesday, September 08, 2015 12:33 PM To: R list Subject: [R] help with reshape Dear users, I'm having troubles with reshaping a data.frame from long to wide format. I copy the output of dput() at the end of the mail because it is quite long. Each row of the column "Elem" should be transposed to a new column. All variables "Etape", "Ech", "repet", "dilution", "Rincage" define the samples. Meaning that for each unique combination of these variables, I want a single row, and as many columns as elements in >> "Elem". So I tried: reshape(mydata, timevar="Elem", idvar=c("Etape","Ech","repet","dilution","Rincage"), direction="wide", drop=c("ID","Nom_ech")) The problem is that some columns are not used at all for defining samples. In this case, the row "S1, F10-3, NA, 1, oui" is missing, but I don't understand why. Can you help me with that? I have no idea what I am doing wrong... Thanks in advance, Ivan 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, 11582, >> 11583, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, >> 696, 697, 698, 699, 700, 701, 702), Nom_ech = c("Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "R1 S1 F1
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 Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89 ivan.calan...@univ-reims.fr https://www.researchgate.net/profile/Ivan_Calandra Le 08/09/15 16:23, David L Carlson a écrit : I have not followed this thread closely, but this seems to work: mydata$repet[is.na(mydata$repet)] <- 0 reshape(mydata, timevar="Elem", idvar=c("Etape","Ech", "repet", "dilution","Rincage"), direction="wide", drop=c("ID","Nom_ech")) If this is the expected outcome, the problem is the NA values in repet. I changed them to 0 since you did not have any 0 entries in the data (otherwise you could use 999 or some other value that does not occur in the data). Change them back after running reshape(). - David L Carlson Department of Anthropology Texas A 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 Petr; R list Subject: Re: [R] help with reshape Thanks Petr, It looks good, but I have to check in more details. Can anyone help me with my original solution using reshape()? I'd like to understand what I did wrong. reshape(mydata, timevar="Elem", idvar=c("Etape","Ech","repet","dilution","Rincage"), direction="wide", drop=c("ID","Nom_ech")) Thank you in advance Ivan -- Ivan Calandra, PhD University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89 ivan.calan...@univ-reims.fr https://www.researchgate.net/profile/Ivan_Calandra Le 08/09/15 14:45, PIKAL Petr a écrit : Hi I looked into docs to reshape2 and played around a bit and by some magical feature test <- dcast(mm, Etape+Ech+repet+dilution+Rincage~Elem) probably works as you expect. I cannot comment your 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 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 column contains maximum one value (the others being NA). Not sure I am being clear... By the way, I don't understand why my solution did not work; what is wrong there? Thank you again! Ivan -- Ivan Calandra, PhD University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89 ivan.calan...@univ-reims.fr https://www.researchgate.net/profile/Ivan_Calandra Le 08/09/15 14:04, PIKAL Petr a écrit : 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=".") names(test)[-(1:5)]<-nn Cheers Petr -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ivan Calandra Sent: Tuesday, September 08, 2015 12:33 PM To: R list Subject: [R] help with reshape Dear users, I'm having troubles with reshaping a data.frame from long to wide format. I copy the output of dput() at the end of the mail because it is quite long. Each row of the column "Elem" should be transposed to a new column. All variables "Etape", "Ech", "repet", "dilution", "Rincage" define the samples. Meaning that for each unique combination of these variables, I want a single row, and as many columns as elements in "Elem". So I tried: reshape(mydata, timevar="Elem", idvar=c("Etape","Ech","repet","dilution","Rincage"), direction="wide", drop=c("ID","Nom_ech")) The problem is that some columns are not used at all for defining samples. In this case, the row "S1, F10-3, NA, 1, oui" is missing, but I don't understand why. Can you help me with that? I have no idea what I am doing wrong... Thanks in advance, Ivan 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, 11582, 11583, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702), Nom_ech = c("Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2", "Step1 B2",
Re: [R] Counting number of rain
Assuming your data is already in R format please sent it dput() format. See ?dput or http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example and http://adv-r.had.co.nz/Reproducibility.html for more details. John Kane Kingston ON Canada > -Original Message- > From: r-help@r-project.org > Sent: Tue, 8 Sep 2015 06:58:58 + (UTC) > To: r-help@r-project.org > Subject: [R] Counting number of rain > > Hello R-users, > I want to ask how to count the number of daily rain data. My data as > below: > Year Month Day Amount 1901 1 1 0 1901 1 2 3 1901 1 3 0 1901 1 4 0.5 1901 > 1 5 0 1901 1 6 0 1901 1 7 0.3 1901 1 8 0 1901 1 9 0 1901 1 10 0 1901 1 > 11 0.5 1901 1 12 1.8 1901 1 13 0 1901 1 14 0 1901 1 15 2.5 1901 1 16 0 > 1901 1 17 0 1901 1 18 0 1901 1 19 0 1901 1 20 0 1901 1 21 0 1901 1 22 0 > 1901 1 23 0 1901 1 24 0 1901 1 25 0 1901 1 26 16.5 1901 1 27 0.3 1901 1 > 28 0 1901 1 29 0 1901 1 30 0 1901 1 31 0 1901 2 1 0 1901 2 2 0 1901 2 3 0 > 1901 2 4 0 1901 2 5 0 1901 2 6 0 1901 2 7 0 1901 2 8 0.3 1901 2 9 0 1901 > 2 10 0 1901 2 11 0 1901 2 12 1 1901 2 13 0.3 1901 2 14 0 1901 2 15 0 1901 > 2 16 0 1901 2 17 0 1901 2 18 0 1901 2 19 0 1901 2 20 0 1901 2 21 0 1901 2 > 22 0 1901 2 23 0.3 1901 2 24 0 1901 2 25 0 1901 2 26 0.3 1901 2 27 0 1901 > 2 28 0 1901 3 1 0 1901 3 2 0.8 1901 3 3 2.3 1901 3 4 0 1901 3 5 0 1901 3 > 6 0 1901 3 7 0 1901 3 8 0 1901 3 9 0 1901 3 10 2 1901 3 11 0 1901 3 12 0 > 1901 3 13 0 1901 3 14 0 1901 3 15 0 1901 3 16 0 1901 3 17 0 1901 3 18 0 > 1901 3 19 0 1901 3 20 0 1901 3 21 0 1901 3 22 1.5 1901 3 23 1.3 1901 3 24 > 0 1901 3 25 0 1901 3 26 0 1901 3 27 0 1901 3 28 0.3 1901 3 29 0.3 1901 3 > 30 4.6 1901 3 31 0 1901 4 1 0 1901 4 2 4.6 1901 4 3 30.7 1901 4 4 0 1901 > 4 5 0 1901 4 6 0 1901 4 7 0 1901 4 8 0 1901 4 9 0 1901 4 10 0 1901 4 11 0 > 1901 4 12 0 1901 4 13 0 1901 4 14 0 1901 4 15 0.3 1901 4 16 1.3 1901 4 17 > 0 1901 4 18 0 1901 4 19 0.3 1901 4 20 1 1901 4 21 9.4 1901 4 22 0.5 1901 > 4 23 0.3 1901 4 24 0 1901 4 25 0 1901 4 26 0 1901 4 27 0 1901 4 28 0 1901 > 4 29 0 1901 4 30 0 1901 5 1 0 1901 5 2 0 1901 5 3 0 1901 5 4 0 1901 5 5 0 > 1901 5 6 0 1901 5 7 0 1901 5 8 0.5 1901 5 9 2.3 1901 5 10 0.3 1901 5 11 > 0 1901 5 12 0 1901 5 13 0 1901 5 14 0 1901 5 15 0 1901 5 16 0 1901 5 17 0 > 1901 5 18 0 1901 5 19 0 1901 5 20 0 1901 5 21 0.5 1901 5 22 0 1901 5 23 0 > 1901 5 24 0 1901 5 25 0 1901 5 26 4.8 1901 5 27 10.9 1901 5 28 3.6 1901 5 > 29 0 1901 5 30 0 1901 5 31 5.1 1901 6 1 0.5 1901 6 2 0 1901 6 3 2 1901 6 > 4 0 1901 6 5 10.2 1901 6 6 33.3 1901 6 7 0.3 1901 6 8 0 1901 6 9 0 1901 > 6 10 0.5 1901 6 11 0.5 1901 6 12 0.3 1901 6 13 2.8 1901 6 14 5.6 1901 6 > 15 0.3 1901 6 16 6.6 1901 6 17 14.2 1901 6 18 4.8 1901 6 19 8.4 1901 6 > 20 1.8 1901 6 21 1.8 1901 6 22 0.3 1901 6 23 8.6 1901 6 24 0 1901 6 25 0 > 1901 6 26 0 1901 6 27 0 1901 6 28 0 1901 6 29 0 1901 6 30 0 1901 7 1 0 > 1901 7 2 0 1901 7 3 0 1901 7 4 0 1901 7 5 1 1901 7 6 0.5 1901 7 7 0.3 > 1901 7 8 0.3 1901 7 9 6.1 1901 7 10 0.3 1901 7 11 1.5 1901 7 12 0 1901 7 > 13 1.5 1901 7 14 0.3 1901 7 15 3.3 1901 7 16 2.3 1901 7 17 0.5 1901 7 18 > 0 1901 7 19 0 1901 7 20 0 1901 7 21 1.8 1901 7 22 0 1901 7 23 1 1901 7 24 > 0.3 1901 7 25 0.3 1901 7 26 1.3 1901 7 27 17 1901 7 28 6.6 1901 7 29 6.1 > 1901 7 30 0.5 1901 7 31 0.3 1901 8 1 0 1901 8 2 0 1901 8 3 0 1901 8 4 0 > 1901 8 5 0 1901 8 6 3.3 1901 8 7 4.1 1901 8 8 0.3 1901 8 9 0 1901 8 10 0 > 1901 8 11 0 1901 8 12 0 1901 8 13 0 1901 8 14 0 1901 8 15 0 1901 8 16 0 > 1901 8 17 0.5 1901 8 18 0 1901 8 19 0 1901 8 20 0 1901 8 21 0 1901 8 22 0 > 1901 8 23 0.3 1901 8 24 1 1901 8 25 0 1901 8 26 0 1901 8 27 10.2 1901 8 > 28 1.5 1901 8 29 0.5 1901 8 30 1.3 1901 8 31 0 1901 9 1 0 1901 9 2 3 > 1901 9 3 1 1901 9 4 0.5 1901 9 5 0.3 1901 9 6 0 1901 9 7 0 1901 9 8 2.3 > 1901 9 9 0.3 1901 9 10 0 1901 9 11 0 1901 9 12 0 1901 9 13 0 1901 9 14 0 > 1901 9 15 0 1901 9 16 0 1901 9 17 0 1901 9 18 1.8 1901 9 19 8.1 1901 9 20 > 0.3 1901 9 21 5.8 1901 9 22 4.1 1901 9 23 0.3 1901 9 24 1.8 1901 9 25 0 > 1901 9 26 0 1901 9 27 0 1901 9 28 0 1901 9 29 1.8 1901 9 30 0.8 1901 10 > 1 0 1901 10 2 0 1901 10 3 0 1901 10 4 0 1901 10 5 0.3 1901 10 6 0 1901 10 > 7 0 1901 10 8 0 1901 10 9 0 1901 10 10 0 1901 10 11 0.3 1901 10 12 3.8 > 1901 10 13 0.4 1901 10 14 9 1901 10 15 2 1901 10 16 1 1901 10 17 0 1901 > 10 18 0 1901 10 19 0 1901 10 20 0.3 1901 10 21 0 1901 10 22 0 1901 10 23 > 0 1901 10 24 0 1901 10 25 0 1901 10 26 0 1901 10 27 14.5 1901 10 28 6.4 > 1901 10 29 0.8 1901 10 30 0 1901 10 31 0 1901 11 1 0 1901 11 2 0 1901 11 > 3 0 1901 11 4 0 1901 11 5 0 1901 11 6 0 1901 11 7 0 1901 11 8 0 1901 11 > 9 0 1901 11 10 0 1901 11 11 0 1901 11 12 5.1 1901 11 13 0.3 1901 11 14 > 5.8 1901 11 15 0 1901 11 16 0 1901 11 17 1 1901 11 18 0.5 1901 11 19 0 > 1901 11 20 0 1901 11 21 0 1901 11 22 0 1901 11 23 0 1901 11 24 0 1901 11 > 25 0.3 1901 11 26 0 1901 11 27 0 1901 11 28 0 1901 11 29 0 1901 11 30 3.3 > 1901 12 1 0 1901 12 2 0 1901 12 3 0 1901 12 4 0 1901 12 5 0 1901 12 6 0 > 1901 12 7 0 1901 12 8 0 1901 12 9
Re: [R] names in R list's
On Tue, Sep 8, 2015 at 7:53 AM, Witold E Wolskiwrote: > Hi Jeff, > > Indeed there was something about plain-text in the r-help posting > guide although I can't find it there anymore. > https://www.r-project.org/posting-guide.html > > Is it still an requirement? Yes. From that very link: Technical details of posting: See General Instructions for more details of the following: No HTML posting (harder to detect spam) (note that this is the default in some mail clients - you may have to turn it off). Note that chances have become relatively high for ‘HTMLified’ e-mails to be completely intercepted (without notice to the sender). -- Sarah Goslee http://www.functionaldiversity.org __ 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] names in R list's
It is not too hard to set up some tests to show time as a function of number of named elements for lists and environments. Here is one such test test <- function (data, nToAdd, nToExtract = length(data)) { addTime <- { addedNames <- paste0("D", seq(length(data) + 1, len = nToAdd)) system.time(for (name in addedNames) data[[name]] <- name) } extractTime <- { names <- sample(names(data), size = nToExtract, replace = TRUE) system.time(for (name in names) tmp <- data[[name]]) } rbind(addTime, extractTime)[, 1:3] } The times for adding and extracting data is pretty linear for environments, at least up to a size of 10^5: > test(new.env(), nToAdd=1e4, nToExtract=5e4) user.self sys.self elapsed addTime 1.4401.44 extractTime 9.3009.30 > test(new.env(), nToAdd=2e4, nToExtract=10e4) user.self sys.self elapsed addTime 2.8702.88 extractTime 18.530 18.55 > test(new.env(), nToAdd=1e5, nToExtract=5e5) user.self sys.self elapsed addTime 14.310 14.32 extractTime 91.950 91.96 but is noticeably quadratic for lists at 10^4 elements: > test(list(), nToAdd=1e4, nToExtract=5e4) user.self sys.self elapsed addTime 1.7001.70 extractTime 2.2302.23 > test(list(), nToAdd=2e4, nToExtract=10e4) user.self sys.self elapsed addTime 5.81 0.025.82 extractTime 9.58 0.009.58 > test(list(), nToAdd=1e5, nToExtract=5e5) user.self sys.self elapsed addTime143.21 0.04 143.29 extractTime255.70 0.00 255.72 For your application you may be interested in timing replacement operations as will. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Sep 8, 2015 at 4:53 AM, Witold E Wolskiwrote: > Hi Jeff, > > Indeed there was something about plain-text in the r-help posting > guide although I can't find it there anymore. > https://www.r-project.org/posting-guide.html > > Is it still an requirement? > > Jeff, thanks for you constructive contribution ;) . Glad that you know > about plain text mode in e-mails, beside doing some perl programming. > I forgot about both. Even the linux admin's I know use python and > thunderbird or some webmail nowadays not pine and perl, but I do not > much networking, so what do I know. > > I think the question I am asking is legitimate. The access complexity > of datastructures is specified in the documentation in case of python > datastructures, java collections or stl containers. > I guess this information is available for name access on R-list but I > just can't find it. > > > > > regards > > On 7 September 2015 at 16:37, Jeff Newmiller > wrote: > > You puzzle me. Why does someone who cannot figure out how to post an > email in plain text after so many messages on this mailing list get all > worried about access time for string indexing? > > > > Environment objects have those properties. They do not solve all > problems though, because they are rather heavyweight... you need a lot of > lookups to pay for their overhead. R5 objects and the hash package both use > them, but I have never found three need to use them. Yes, I do program in > Perl so I know where you are coming from, but the vector-based name lookup > used in R works quite effectively for data where the number of list items > is short or where I plan to access every element as part of my data > processing anyway. > > > --- > > Jeff NewmillerThe . . Go > Live... > > DCN: Basics: ##.#. ##.#. Live > Go... > > Live: OO#.. Dead: OO#.. Playing > > Research Engineer (Solar/BatteriesO.O#. #.O#. with > > /Software/Embedded Controllers) .OO#. .OO#. > rocks...1k > > > --- > > Sent from my phone. Please excuse my brevity. > > > > On September 7, 2015 3:34:53 AM PDT, Witold E Wolski > wrote: > >>What is the access time for R lists given a name of list element, is it > >>linear, log, or constant? > >> > >>Than what are to rules for names in R-lists > >> > >>That reusing names is possible makes me wonder. > >> > >>tmp <- as.list(c(1,2,3,4)) > >>names(tmp) = c("a","a","b","b") > >>tmp > >>tmp$a > >> > >> > >>What I am looking for is a standard R data structure which will allow > >>me > >>for fast and name lookup. > > > > > > -- > Witold Eryk Wolski > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the
[R] Extracting case values from ancova adjusted means
Dear Help List, Given a standard one-way ANCOVA model for comparing k groups and with one covariate factor e.g. ANC <- lm(Y ~ X + Group) run within package "car" followed by the estimation of adjusted group means with the "effects" package e.g. Effects1 <- Effect("Group", ANC, se = TRUE) how can I extract the individual case values adjusted to the covariate grand mean that theoretically go into creating each adjusted group mean and its confidence interval? I recognize that summary computational formulae are probably used to estimate adjusted group means and their SE and the package "effects" may not even calculate individual case adjusted values. Use of the "fitted" command applied to the ANC model e.g. Fitted1 <- fitted(ANC) produces case values that do not average to the adjusted mean for each group output by "Effects" while applying "fitted" to the Effects output results in NULL. I am unsure why the first result occurs and the second outcome may result from having applied a command i! nappropriately. A function may need to be created to estimate case adjusted values but that is, at this time, beyond me. I have read the "effects" package pdf but found nothing to enlighten me on this issue. I have estimated adjusted case values in Excel using Yij(adj) = yij - b(xij - xbar) where b is the slope of the pooled Group regression and xbar is the grand mean X but the mean of the adjusted case values for a group do not always match the adjusted group means from the Effects or even the fitted command output as closely as I think they should (to at least 3 decimals given the data are log transformed) even after allowing for decimal rounding because I used only 5 places in Excel. Thanks for any assistance in how to extract the case values used to create the adjusted group means from an ANCOVA by the "effects" package such that the mean of the case values for a group equals the adjusted mean for that group. Regards, B. Jessop [[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] R wont accept my zero count values in the GLM with quasi_poisson dsitribution
Hello I am going to look at the ZIP (zero-inflated poisson). I just need to ask. One of my variables is continuous data (hosts body length), is it ok to include this kind of data into this analysis or do I need to turn it into categories (29-50 mm, 51-100mm and so on)? Many Thanks Charlotte -- View this message in context: http://r.789695.n4.nabble.com/R-wont-accept-my-zero-count-values-in-the-GLM-with-quasi-poisson-dsitribution-tp4710462p4712029.html Sent from the R help mailing list archive at Nabble.com. __ 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] R wont accept my zero count values in the GLM with quasi_poisson dsitribution
based on your code "fit <- glm(abundance~Gender,data=teminfest,family=binomial())", i don't see anything related to quasi_poisson. are you sure what you are doing here? On Tue, Jul 28, 2015 at 1:33 AM, Charlottewrote: > Hello > > I have count values for abundance which follow a pattern of over-dispersal > with many zero values. I have read a number of documents which suggest that > I don't use data transforming methods but rather than I run the GLM with the > quasi poisson distribution. So I have written my script and R is telling me > that Y should be more than 0. > > Everything I read tells me to do it this way but I can't get R to agree. > Did I need to add something else to my script to get it to work and keep my > data untransformed? The script I wrote is as follows: > >> fit <- glm(abundance~Gender,data=teminfest,family=binomial()) > > then I get this error > Error in eval(expr, envir, enclos) : y values must be 0 <= y <= 1 > > I don't use R a lot so I am having trouble figuring out what to do next. > > I would appreciate some help > > Many Thanks > Charlotte > > > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/R-wont-accept-my-zero-count-values-in-the-GLM-with-quasi-poisson-dsitribution-tp4710462.html > Sent from the R help mailing list archive at Nabble.com. > > __ > 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. -- WenSui Liu https://statcompute.wordpress.com/ __ 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] Non linear regression - Von Bertalanffy Growth Function - "singular gradient matrix at initial parameter estimates"
Thank you for the tip. Indeed, nlxb in nlmrt works and results are not crazy. I would like however to assess goodness-of-fit (gof) and ultimately to compare it with gof from linear regression (fitted with same variables). Before I used AICc to compare the nls() and lm() fit, however I get now an error message concerning the method loglike and its non compatibility with nlmrt class object. I guess it is because we use now Marquardt method to minimise sum-of square instead of Gauss-Newton? I am right? Or this is just an incompatibility coming between AICc function and nlmrt objects? Is there an R function to do that? Best, Xochitl C. <>< <>< <>< <>< Xochitl CORMON +33 (0)3 21 99 56 84 Doctorante en écologie marine et science halieutique PhD student in marine ecology and fishery science <>< <>< <>< <>< IFREMER Centre Manche Mer du Nord 150 quai Gambetta 62200 Boulogne-sur-Mer <>< <>< <>< <>< Le 19/08/2015 15:11, ProfJCNash a écrit : Packages nlmrt or minpack.lm use a Marquardt method. minpack.lm won't proceed if the Jacobian singularity is at the starting point as far as I'm aware, but nlxb in nlmrt can sometimes get going. It has a policy that is aggressive in trying to improve the sum of squares, so will use more effort than nls when both work. JN On 15-08-18 12:08 PM, Xochitl CORMON wrote: Dear all, I am trying to estimate VBGF parameters K and Linf using non linear regression and nls(). First I used a classic approach where I estimate both parameters together as below with "alkdyr" being a subset per year of my age-length-key database and running in a loop. vbgf.par <- nls(Lgtcm ~ Linf *(1 - exp(-K * (Age - tzero))), start = c(K= 0.07, Linf = 177.1), data=alkdyr) I obtain an estimation of both parameters that are strongly correlated. Indeed after plotting Linf ~ K and fitting a linear regression I obtain a function (Linf = a + b*K) with R2= 0.8 and a = 215, b = -763. In this context, to take into account explicitly correlation between parameters, I decided to fit a new non linear regression derivate from VBGF but where Linf is expressed depending on K (I am most interested in K). To do so, I tried this model: vbgf.par <- nls(Lgtcm ~ (a + (b*k)) *(1 - exp(-k * (Age - tzero))), start = c(k= 0.07, a= 215, b=-763), data=alkdyr) Unfortunately at this point I cannot go further as I get the error message "singular gradient matrix at initial parameter estimates". I tried to use alg= plinear (which I am not sure I understand properly yet). If I give a starting value for a and b only, I have an error message stating "step factor below minFactor" (even when minFactor is set to 1000). Any help will be more than welcome as this is quite urgent Best, Xochitl C. __ 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] Counting number of rain
Try the following: ## step 1: write raw data to an array junk<-scan('clipboard') # entering the numbers (not the 'year' etc. labels) into R as a vector after junk<-t(array(junk,dim=c(4,length(junk)/4))) # convert the vector into a 2-d array with 4 columns (year, month, day, amount) ## step 2: create a dataframe to store and display the results nyr<-length(unique(junk[,1])) ans<-data.frame(array(dim=c(nyr,12))) # a dataframe for storing the results names(ans)<-c('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec') yrs<-sort(unique(junk[,1])) row.names(ans)<-yrs # step 3: calculate for (yi in 1:nyr){ # loop through the years... for (mi in 1:12){ # ...and the months ans[yi,mi]<-sum(junk[junk[,1]==yrs[yi] & junk[,2]==mi,4]>0.01) # count the rainy days by # first subsetting the junk array by rows that match the given year and month and sum } } Does that help? - Dan -- View this message in context: http://r.789695.n4.nabble.com/Counting-number-of-rain-tp4712007p4712011.html Sent from the R help mailing list archive at Nabble.com. __ 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] 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 that would defeat the whole purpose of flagging the value as missing. Similar results occur if you try to create tables or cross-tabulations of variables that include NAs with table() and xtabs(). David -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ivan Calandra Sent: Tuesday, September 8, 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 Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89 ivan.calan...@univ-reims.fr https://www.researchgate.net/profile/Ivan_Calandra Le 08/09/15 16:23, David L Carlson a écrit : > I have not followed this thread closely, but this seems to work: > > mydata$repet[is.na(mydata$repet)] <- 0 > reshape(mydata, timevar="Elem", idvar=c("Etape","Ech", "repet", > "dilution","Rincage"), > direction="wide", drop=c("ID","Nom_ech")) > > If this is the expected outcome, the problem is the NA values in repet. I > changed them to 0 since you did not have any 0 entries in the data (otherwise > you could use 999 or some other value that does not occur in the data). > Change them back after running reshape(). > > - > David L Carlson > Department of Anthropology > Texas A 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 Petr; R list > Subject: Re: [R] help with reshape > > Thanks Petr, > It looks good, but I have to check in more details. > > Can anyone help me with my original solution using reshape()? I'd like > to understand what I did wrong. > reshape(mydata, timevar="Elem", > idvar=c("Etape","Ech","repet","dilution","Rincage"), direction="wide", > drop=c("ID","Nom_ech")) > > Thank you in advance > Ivan > > -- > Ivan Calandra, PhD > University of Reims Champagne-Ardenne > GEGENAA - EA 3795 > CREA - 2 esplanade Roland Garros > 51100 Reims, France > +33(0)3 26 77 36 89 > ivan.calan...@univ-reims.fr > https://www.researchgate.net/profile/Ivan_Calandra > > Le 08/09/15 14:45, PIKAL Petr a écrit : >> Hi >> >> I looked into docs to reshape2 and played around a bit and by some magical >> feature >> >> test <- dcast(mm, Etape+Ech+repet+dilution+Rincage~Elem) >> >> probably works as you expect. >> >> I cannot comment your 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 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 >>> column contains maximum one value (the others being NA). >>> >>> Not sure I am being clear... >>> >>> By the way, I don't understand why my solution did not work; what is >>> wrong there? >>> >>> Thank you again! >>> Ivan >>> >>> -- >>> Ivan Calandra, PhD >>> University of Reims Champagne-Ardenne >>> GEGENAA - EA 3795 >>> CREA - 2 esplanade Roland Garros >>> 51100 Reims, France >>> +33(0)3 26 77 36 89 >>> ivan.calan...@univ-reims.fr >>> https://www.researchgate.net/profile/Ivan_Calandra >>> >>> Le 08/09/15 14:04, PIKAL Petr a écrit : 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=".") names(test)[-(1:5)]<-nn Cheers Petr > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ivan > Calandra > Sent: Tuesday, September 08, 2015 12:33 PM > To: R list > Subject: [R] help with reshape > > Dear users, > > I'm having troubles with reshaping a data.frame from long to wide > format. > I copy the output of dput() at the end of the mail because it is > quite long. > > Each row of the column "Elem" should be transposed to a new column. > All variables "Etape", "Ech", "repet",
Re: [R] Laplace smoothing in J48
Without a reproducible example that includes some sample data provided using dput() (fake is fine), the code you used, and some clear idea of what output you expect, it's impossible to figure out how to help you. Here are some suggestions for creating a good reproducible example: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example On Tue, Sep 8, 2015 at 2:10 AM, Priyanka Gargwrote: > Hi, > > I am using J48 classifier. I want to now after i set A as TRUE in control > option of the classifier, how could i see its effect when using predict > method ? > > > > Regards > Priyanka Garg > School of Computers & Information Sciences > University Of Hyderabad > > [[alternative HTML version deleted]] -- Sarah Goslee http://www.functionaldiversity.org __ 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 me in cluster
I have project to study and analysis clusters algorithm in R "K-mean, Hierarchical, Density based and EM" I want to calculate Cluster instance , number of iteration , sum of squared error SSE and the accuracy for each cluster algorithms that i mention above And the log likelihood for EM and DBSCAN I wrote code in r for "K-mean, Hierarchical, Density based and EM But i can't calculate Cluster instance , number of iteration , sum of squared error SSE and the accuracy for each cluster algorithms that i mention above And the log likelihood for EM and DBSCAN [[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] Help with vectors!
On Sat, Sep 05, 2015 at 02:14:18PM -0700, Dan D wrote: > # your data > VAS<-c("Green","Green","Black","Green","White","Yellow","Yellow","Black","Green","Black") > > # declare the new vector > New_Vector<-numeric(length(VAS)) > > # brute force: > New_Vector[VAS=="White"]<-1 > New_Vector[VAS=="Yellow"]<-2 > New_Vector[VAS=="Green"]<-3 > New_Vector[VAS=="Black"]<-4 > > # a little more subtle > cols<-c("White","Yellow","Green","Black") > for (i in 1:length(cols)) New_Vector[VAS==cols[i]]<-i > > # and a general approach (that may give a different indexing, but can be > used for any array) > for (i in 1:length(unique(VAS))) New_Vector[VAS==unique(VAS)[i]]<-i > cbind(1:length(unique(VAS)),unique(VAS)) # a decoding key for the color > index > # how about: rank( VAS, ties.method='min') Regards __ 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] mlogit data format
Ok, here is my question. I have a data frame that looks like this: yx1 x2 (say, age)x3 yes car 23 catholic no bus34 muslim maybe bus16 jew You see, the multinomial dependent variable is y, but I also have multi-factors in the right side of the equation. I want to use mlogit, but it seems to me that my database isn't like the examples in the package's vignette. Say my dataframe is "new". I don't know if it's just: new1<-mlogit.data(new, choice="y", shape="long", alt.levels=c("yes", "no", "maybe")) Or should I also input levels for x1 and x3? Any help would be appreciated. Thanks a lot Obrigado / Thanks for your time and attention. Claudio D. Shikida http://www.cdshikida.net and http://works.bepress.com/claudio_shikida/ Esta mensagem pode conter informação confidencial e/ou privilegiada. Se você não for o destinatário ou a pessoa autorizada a receber esta mensagem, não poderá usar, copiar ou divulgar as informações nela contidas ou tomar qualquer ação baseada nessas informações. Se você recebeu esta mensagem por engano, por favor avise imediatamente o remetente, respondendo o presente e-mail e apague-o em seguida. This message may contain confidential and/or privileged ...{{dropped:9}} __ 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] groups Rank
many thanks, It WORKS. But what If I want to add a condition that considered Measure_id , if it is '1' rank reverse the probability and if it is ' 2 ' rank is ordered like probability? Replying is highly appreciated Ragia > From: petr.pi...@precheza.cz > To: ragi...@hotmail.com; r-help@r-project.org > Subject: RE: [R] groups Rank > Date: Mon, 7 Sep 2015 09:29:21 + > > Hi > > OK, thanks for sending dput result. > > I am still not sure what exactly you want. Using ?ave you can get result of > x/max(x) > > dat$prob <- ave(dat$value, paste(dat$id, dat$i), FUN= function(x) x/max(x)) > > however in case max(x) is zero the result is NA > > You can change it to zero > > dat$prob[is.nan(dat$prob)] <- 0 > > and compute rank value by similar process. > > dat$rankvalue <- ave(dat$prob, paste(dat$id, dat$i), FUN = rank) > > But I am not sure if this is the desired result. > > Cheers > Petr > > >> -Original Message- >> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ragia >> Ibrahim >> Sent: Monday, September 07, 2015 10:12 AM >> To: Sarah Goslee; r-help@r-project.org >> Subject: Re: [R] groups Rank >> >> apology for re sending the Email, I changed the format to plain text as >> I have been advised the data is as follow >> >> thanks Sarah, >> I used pdut, and here is the data as written on R..I attached the dput >> result structure(list(Measure_id = c(1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, >> 3, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, >> 3, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3), i = c(5, 5, 5, 5, 5, 5, 5, 5, >> 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, >> 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7), j = c(1, 1, 1, 1, 1, >> 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, >> 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), id = c(1, 2, >> 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, >> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, >> 11, 12), value = c(2, 1.5, 0, 0, 1, 0.5, 0, 0, 0, 0, 0.5, 2, 2, 1.5, 0, >> 1, 2, 0, 0.5, 1.44269504088896, 0, 0, 0, 0, 1, 1.5, 0, 0, 1, 0, 0, 0, >> 0, 0, 0, 0, 1, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0)), .Names = >> c("Measure_id", "i", "j", "id", "value"), row.names = c(NA, 48L), class >> = "data.frame") >> >> the data is as follow : >> >> Measure_id i j id value >> 1 1 5 1 1 2.0 >> 2 1 5 2 1 2.0 >> 3 1 5 1 2 1.5 >> 4 1 5 2 2 1.5 >> 5 1 5 1 3 0.0 >> 6 1 5 2 3 0.0 >> 7 1 5 1 4 0.0 >> 8 1 5 2 4 1.0 >> 9 1 5 1 5 1.0 >> 10 1 5 2 5 2.0 >> .. ... . . .. ... >> I want to add a probability column, the prob column depends on id >> grouped by for each i the rank will be current (value / max value ) for >> the same id for specific i, it would be >> >> Measure_id i j id value prob >> 1 1 5 1 1 2.0 2/2 >> 2 1 5 2 1 2.0 2/2 >> 3 1 5 1 2 1.5 1.5/1.5 >> 4 1 5 2 2 1.5 1.5/1.5 >> 5 1 5 1 3 0.0 0 >> 6 1 5 2 3 0.0 0 >> 7 1 5 1 4 0.0 0/1 >> 8 1 5 2 4 1.0 1/1 >> 9 1 5 1 5 1.0 1/2 >> 10 1 5 2 5 2.0 2/3 >> .. ... . . .. ... >> >> then I want to add a rank column that rank regarding probability, if >> the probability equal they took the same rank for the same id belongs >> to the same i, otherwize lower probability took higher rank for examole >> if we have three values for i=7 and for the three values the id is 1 >> and the probability is ( .2,.4,.5) the rank should be 3,2,1 >> >> >> >> I looked at aggregate and dplyr...should I use for loop and subset each >> i and id rows do calculations and then group them again ?? >> is there easier way? >> >> replying highly appreciated >>> >>> >>> Date: Sun, 6 Sep 2015 19:02:02 -0400 Subject: Re: [R] groups Rank From: sarah.gos...@gmail.com To: ragi...@hotmail.com CC: r-help@r-project.org Please use dput() to provide data, rather than expecting people to open random attachments. Besides, there are multiple options for getting data into R, and we need to know exactly what you did. >> dput() is faster and easier. What have you tried? Did you look at aggregate() as I suggested? Sarah On Sat, Sep 5, 2015 at 10:44 AM, Ragia Ibrahim>> wrote: > thanks for replying, I attached the data frame for source "i" I >> want > to sum the values and get the max value then add a new column >> called > rank . That new column cell value for each source i and for >> specific > id would be (value/max value) * count of rows that have the same > criteria "same i and same id" > > many thanks > Ragia > >> Date: Fri, 4 Sep 2015 10:19:35 -0400 >> Subject: Re: [R] groups Rank >> From: sarah.gos...@gmail.com >> To: ragi...@hotmail.com >> CC: r-help@r-project.org >> >> Hi Ragia, >> >> I can't make out your data or desired result, but it sounds like >> aggregate() might get you started. If you need more help, please >>
[R] Task Views
Dear All I am using R version R version 3.2.1 (2015-06-18) in windows 7. I have installed few task views like Timeseries and Graphics in R. 1. Is it possible to find out which "TASK Views" are installed in the system ? 2. Can in install multiple Task views using single command ? Regards Partha __ 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.