[R] create zoo object within a for loop
David Winsemius
dwinsemius at comcast.net
Thu Oct 15 20:44:26 CEST 2015
On Oct 15, 2015, at 4:07 AM, Wiebke Ullmann wrote:
> Dear everyone.
>
> I have a data frame with relocation data of several animals
>
>> head(data)
It would be better to post output of dput(head(data))
>
> timestamp
>
>
> individual
>
>
> easting
>
>
> northing
>
snipped larg amount of useless output
>
> 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]]
You need to change settings in your mail client so you are adhering to the plain-text requirements of the mail-server offered by ETHZ. And please read the posting guide.
> ______________________________________________
> R-help at 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.
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list