Hi everyone, Once again I am stuck with a problem I can't seem to figure out. I suppose this learning curve levels off eventually, lol. I am learning on my own with absolutely no background in programming, so if I seem to request help a lot it's not because I am seeking others to do the work for me. I need to assign one of two arrival times to the 'ARRIVE' variable of my dataframe, and I want a value assigned only to the first element of each 'MM' by 'DD' variable grouping. The value used (either 0700 or 1430) will be conditional on the value in the 'TOD' variable, such that if 'TOD' == 1, 'ARRIVE'<-0700, and if 'TOD'==2, 'ARRIVE'<-1430. I want the remaining three 'MM' by 'DD' values for each unique grouping to remain "NA" for now, because I intend to calculate them later. I have tried ifelse statements with ddply, for loops, etc. to no avail. Any help would be greatly appreciated. Thank you, Mike -------------- next part -------------- A non-text attachment was scrubbed... Name: Dataframe.pdf Type: application/pdf Size: 85978 bytes Desc: Dataframe.pdf URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100316/1f8b51af/attachment.pdf>
Hi everyone, Once again I am stuck with a problem I can't seem to figure out. I suppose this learning curve levels off eventually, lol. I am learning on my own with absolutely no background in programming, so if I seem to request help a lot it's not because I am seeking others to do the work for me. I need to assign one of two arrival times to the 'ARRIVE' variable of my dataframe, and I want a value assigned only to the first element of each 'MM' by 'DD' variable grouping. The value used (either 0700 or 1430) will be conditional on the value in the 'TOD' variable, such that if 'TOD' == 1, 'ARRIVE'<-0700, and if 'TOD'==2, 'ARRIVE'<-1430. I want the remaining three 'MM' by 'DD' values for each unique grouping to remain "NA" for now, because I intend to calculate them later. I have tried ifelse statements with ddply, for loops, etc. to no avail. Any help would be greatly appreciated. Thank you, Mike -------------- next part -------------- A non-text attachment was scrubbed... Name: Dataframe.pdf Type: application/pdf Size: 85978 bytes Desc: Dataframe.pdf URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100316/3c37f7c1/attachment.pdf>
On Mar 16, 2010, at 3:44 PM, Hosack, Michael wrote:> Hi everyone, > > Once again I am stuck with a problem I can't seem to figure out. I > suppose this learning curve levels off eventually, lol. I am > learning on my own with absolutely no background in programming, so > if I seem to request help a lot it's not because I am seeking others > to do the work for me. I need to assign one of two arrival times to > the 'ARRIVE' variable of my dataframe, and I want a value assigned > only to the first element of each 'MM' by 'DD' variable grouping. > The value used (either 0700 or 1430) will be conditional on the > value in the 'TOD' variable, such that if 'TOD' == 1, > 'ARRIVE'<-0700, and if 'TOD'==2, 'ARRIVE'<-1430. I want the > remaining three 'MM' by 'DD' values for each unique grouping to > remain "NA" for now, because I intend to calculate them later. I > have tried ifelse statements with ddply, for loops, etc. to no > avail. Any help would be greatly appreciated.Logical indexing; dfrm[!duplicated(paste(dfrm$MM, dfrm$DD)), "ARRIVE"] <- "0700" dfrm$ARRIVE[dfrm$ARRIVE == "0700" & dfrm$TOD=="2"] <- "1430" -- David Winsemius, MD West Hartford, CT