[R] How to extract Friday data from daily data.

thornbird huachang396 at gmail.com
Tue Nov 9 17:23:44 CET 2010


Thanks for your suggestion. I received a few error messages. Can anyone help
me figure out why I get the following error messages and how to solve them
by revising my code? The data is shown in the post above. Thanks.


> library(zoo)
>
> colClasses <- c("character", "character", "numeric", "character",
> "character", "numeric")
>
> col.names <- c("date", "day", "time", "webpage", "item", "value")
>
> # z <- read.zoo("myfile.dat", skip = 1, index = as.list(1:5),
> z <- read.zoo(testdata[,1:5],as.Date(as.character(testdata[, 1])),skip =
> 1, index = as.list(1:6),
+         format = "%d/%m/%Y", col.names = col.names,
+         aggregate = function(x) tail(x, 1), colClasses = colClasses)
Error in `[.data.frame`(rval, , j) : undefined columns selected
>
>
> # extract all Thursdays and Fridays
> z45 <- z[format(time(z), "%w") %in% 4:5,]
Error: object 'z' not found
>
> # keep last entry in each week
> # and show result on R console
> z45[!duplicated(format(time(z45), "%U"), fromLast = TRUE), ]
Error: object 'z45' not found
-- 
View this message in context: http://r.789695.n4.nabble.com/How-to-extract-Friday-data-from-daily-data-tp3029050p3034553.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list