[R] Odp: Dataframe manipulation

Petr PIKAL petr.pikal at precheza.cz
Fri Mar 19 09:15:50 CET 2010


Hi

maybe you shall be a little bit more clear what you really want. It is 
hard to copy your data o R without some extensive fiddling, so we need to 
rely on complicated text description.

It seems that 
?ave
could help you but it is hard to check.

Basically I would recode ARRIVE and DEPART as POSIX class as I suggested 
before. Then you can do some arithmetic with it.

At least you shall tell us what you want to be in second value for ARRIVE.

If your task is not repeating and size of your data is not too big 
probably some looping could be also suitable. Or also zoo and function 
na.locf can help but without data, shrug.

Sorry that I can not provide canned help but I am really not sure what the 
output shall be.

Regards
Petr



r-help-bounces at r-project.org napsal dne 18.03.2010 14:48:06:

> 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
> [příloha Dataframe.pdf odstraněna uživatelem Petr PIKAL/CTCAP] 
> ______________________________________________
> 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.



More information about the R-help mailing list