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

thornbird huachang396 at gmail.com
Mon Nov 8 03:10:43 CET 2010


Hi thanks for quick reply. I am new to using R and still tried to figure out
how to use Zoo package.

Here is the code I have so far:

library(zoo)

colClasses <- c("NULL", "character", "character", "numeric", "character",
"character", "NULL")

col.names <- c(NA, "webpage", "item", "value", "day", "date", NA)

# z <- read.zoo("myfile.dat", skip = 1, index = as.list(1:6),
z <- read.zoo("C:\\Users\\Kevin\\Desktop\\testdata.csv", sep = ",", skip =
1, index = as.list(1:6),
        format = "%d/%m/%Y", col.names = col.names,
        aggregate = function(x) tail(x, 1), colClasses = colClasses)


# extract all Thursdays and Fridays
z45 <- z[format(time(z), "%w") %in% 4:5,]

# keep last entry in each week
# and show result on R console
z45[!duplicated(format(time(z45), "%U"), fromLast = TRUE), ]



I attached a reproducible dataset in excel    
http://r.789695.n4.nabble.com/file/n3031422/testdata.csv testdata.csv    
and I hope to get the results as follows. It would be great if I can get all
days in Friday format as you suggested in the second approach the first
time.

Again your time and help is appreciated!

webpage item value        day date       time
MattDamon fans 642045 Thu 11-Jun-09 22:11:33
MattDamon fans 765057 Fri 19-Jun-09 12:37:09
MattDamon fans 899900 Sat 27-Jun-09 12:40:36  (no Fri or Thu, so I chose
Sat)
MattDamon views 642045 Thu 11-Jun-09 22:11:33
MattDamon views 765057 Fri 19-Jun-09 12:37:09
MattDamon views 887195 Fri 26-Jun-09 13:36:12
AngieeJolie fans 642045 Thu 11-Jun-09 22:11:33
AngieeJolie fans 765057 Fri 19-Jun-09 12:37:09
AngieeJolie fans 887195 Fri 26-Jun-09 13:36:12
AngieeJolie views 642045 Thu 11-Jun-09 22:11:33
AngieeJolie views 765057 Fri 19-Jun-09 12:37:09
AngieeJolie views 887195 Fri 26-Jun-09 13:36:12 
-- 
View this message in context: http://r.789695.n4.nabble.com/How-to-extract-Friday-data-from-daily-data-tp3029050p3031422.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list