[R] offlist Re: Dataframe manipulation

Hosack, Michael mhosack at state.pa.us
Thu Mar 18 15:53:40 CET 2010


David,

A quick correction. I have been posting for less than one month (my first posting was Mar 5, verify if so inclined). Thank you for making me aware of dput and dump capabilities, I will use them in future posts. Secondly, I would assume that all of us are either directly or indirectly seeking assistance with 'work' related R issues, either for a government agency, in school as preparation for future paid work, or in academics where one receives a salary for doing research, among other things. So, I don't see the relevance of your second point.  I doubt anyone here is learning R for the fun of it. I would rather be fishing, lol. I think my attached dataframe clearly shows what I want to do, and all I really want is some specific guidance (i.e. given relevant functions, etc.). I would LOVE to code this on my own. Thank you for your help thus far.

Mike


-----Original Message-----
From: David Winsemius [mailto:dwinsemius at comcast.net] 
Sent: Thursday, March 18, 2010 10:31 AM
To: Hosack, Michael
Subject: offlist Re: [R] Dataframe manipulation

Here's why I am not taking this one one. You've been posting similar  
problems for the last 6 months and you still have not learned how to  
use dput or dump to create cut and pastable R object descriptions...  
plus this looks like its a job and you are asking us to do your  
work... but that's only of secondary importance. It's the first  
concern that is primary. You are asking us to figure out what your  
data really looks like and repeat lots of steps that are already done.

-- 
David.

On Mar 18, 2010, at 9:48 AM, Hosack, Michael wrote:

> Hello R users,
>
> I spent most of my workday yesterday trying unsuccessfully to
> write code that will perform a series of calculations on my
> dataframe (partial copy is attached). What I need to do is
> multiply the 24 hr time in the 'DEPART' column by the time
> (in the 'TRAVEL' column (travel time in minutes), and store this
> result in the 'ARRIVE' column for the following 'SITE1' number.
> Then I need to add the 'WAIT' time (minutes) for that site's row
> to its 'ARRIVE' time to calculate the next 'DEPART' time and
> then proceed down the dataframe independently for each unique 'MM'
> by 'DD' combination. What I want to do I hope will be obvious after  
> you
> view the dataframe. Basically, for each unique 'MM' (month) by  
> 'DD'(day) grouping
> I have four sites that are surveyed sequentially, and the starting
> site for a survey day was chosen randomly. The route is circular,
> proceeding from site 101 to 104. I really hope someone can help
> me with this, because I am so close to finishing it.
>
> BTW, the code that adds minutes to 24 hr time to create 24 hr time  
> is as follows:
>
> addTime2<-function(timeTxt,mins){
> orig.date<-as.POSIXct(paste("2001-01-01",timeTxt))
> new.Date<-orig.date+mins*60
> new.Date<-strsplit(as.character(new.Date)," ")
> new.Time<-(sapply(new.Date,"[",2))
> return(new.Time)
> }
> SCHEDULE2$DEPART<-addTime2(SCHEDULE2$ARRIVE,SCHEDULE2$WAIT)
> (code courtesy of Gustaf)
>
> Thank you,
>
> Mike
> <Dataframe.pdf>______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list