[R] create zoo object within a for loop
Dear everyone. I have a data frame with relocation data of several animals >head(data) timestamp individual easting northing 25.03.2014 07:00 animal1 410712.5 5913542 25.03.2014 08:00 animal1 410716.8 5913536 25.03.2014 12:00 animal1 410717.9 5913538 25.03.2014 17:00 animal1 410814.2 5913827 25.03.2014 18:00 animal1 410577.2 5912917 25.03.2014 19:00 animal1 410188.2 5913556 25.03.2014 20:00 animal1 410413.8 5913581 25.03.2014 21:00 animal1 409929.5 5913376 25.03.2014 22:00 animal1 410007.5 5913425 25.03.2014 07:00 animal2 410712.5 5913542 25.03.2014 08:00 animal2 410716.8 5913536 25.03.2014 12:00 animal2 410717.9 5913538 25.03.2014 17:00 animal2 410814.2 5913827 25.03.2014 18:00 animal2 410577.2 5912917 25.03.2014 19:00 animal2 410188.2 5913556 25.03.2014 20:00 animal2 410413.8 5913581 25.03.2014 21:00 animal2 409929.5 5913376 25.03.2014 22:00 animal2 410007.5 5913425 26.03.2014 08:00 animal3 410546.3 5913590 26.03.2014 09:00 animal3 410668.3 5913467 26.03.2014 10:00 animal3 410665.3 5913556 26.03.2014 11:00 animal3 410652.9 5913450 26.03.2014 12:00 animal3 410649.4 5913464 Some hours in the timestamp are missing. I would like to fill the timestamp with the missing hours and the other variables with the last occuring information. It should look like this: timestamp individual easting northing 25.03.2014 07:00 animal1 410712.5 5913542 25.03.2014 08:00 animal1 410716.8 5913536 25.03.2014 09:00 animal1 410716.8 5913536 25.03.2014 10:00 animal1 410716.8 5913536 25.03.2014 11:00 animal1 410716.8 5913536 25.03.2014 12:00 animal1 410717.9 5913538 ... I know how to do this with a data frame that only includes the information of one animal. I used an index in zoo: >animal1$time <- strptime(animal1$timestamp, format="%Y-%m-%d %H:%M:%S") >animal1$time <- as.POSIXct(format(round(animal1$time, units="hours"), format="%Y-%m-%d %H:%M")) >animal1.zoo <- zoo(animal1[,-5],animal1[,5]) #set Index >animal1m <- merge(animal1.zoo, zoo(,seq(animal1[1,5],animal1[length(animal1$timestamp),5],by="hour")), all=TRUE) And filled the other variables with na.locf. But I do not know how to do this in one go for all the animals. I would like to use a for loop or lappy for lists. I would be very glad if you could help me out. Thank you very much in advance. Cheers, Vivi [[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.
[R] ltraj contains irregular data
Dear everyone, as far as I understood the setNA function in adhabitat is there to produce rows in a location dataset that have not been recorded by the GPS collar. I just can not figure out where the problem is. Hope somebody can help me. >daten$timestamp <- strptime(daten$study.local.timestamp, format="%Y-%m-%d %H:%M") >format(round(daten$timestamp, units="hours"), format="%Y-%m-%d %H:%M:%S") >daten$timestamp <- as.POSIXct(daten$timestamp,format="%Y-%m-%d %H:%M:%S") >u<-as.ltraj(daten[,c("utm.easting","utm.northing")], daten$timestamp,id=daten$tag.local.identifier, infolocs=daten[,c("tag.local.identifier", "individual.local.identifier")]) >head([[1]]) x ydatedxdy dist 407063.1 5911535 2014-05-12 16:00:00 53.75844 -8.434472e+01 100.0200 407116.9 5911451 2014-05-12 17:00:00 -417115.85704 -5.921450e+06 5936122.8652 -.0 - 2014-05-12 18:00:00 0.0 0.00e+00 0. -.0 - 2014-05-12 20:00:00 417008.07372 5.921561e+06 5936226.4139 407009.1 5911562 2014-05-12 21:00:00 156.63876 1.096218e+02 191.1874 407165.7 5911672 2014-05-12 23:00:00 NANA NA dt R2n abs.angle rel.angle 3600 3.523851e+13 -1.0033541 -2.5038352 3600 3.523755e+13 -1.6411217 -0.6377675 7200 0.00e+00 NA NA 3600 0.00e+00 1.5004904 -3.1415732 7200 3.523878e+13 0.6106172 -0.8898732 NA 3.524021e+13 NA NA >nex <- setNA(u,u[[1]]$date[1], 1*3600) Fehler in FUN(X[[i]], ...) : ltraj contains irregular data (time lag > or < tol) If you need any additional information on what I have done I am happy to provide it (I am not sure what you need to be able to help). Thank you soo much in advance. Cheers, Wiebke [[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.