Hey,

This should work, but after you read in your data make sure that your day,
date and time are separate, this should work just fine, or something like
it.

> testdata
    views  number  timestamp  day       date     time
1  views  910401 1246192687 Sun 6/28/2009 12:38
2  views  921537 1246278917 Mon 6/29/2009 12:35
3  views  934280 1246365403 Tue 6/30/2009 12:36
4  views  986463 1246888699 Mon  7/6/2009 13:58
5  views  995002 1246970243 Tue  7/7/2009 12:37
6  views 1005211 1247079398 Wed  7/8/2009 18:56
7  views 1011144 1247135553 Thu  7/9/2009 10:32
8  views 1026765 1247308591 Sat 7/11/2009 10:36
9  views 1036856 1247436951 Sun 7/12/2009 22:15
10 views 1040909 1247481564 Mon 7/13/2009 10:39
11 views 1057337 1247568387 Tue 7/14/2009 10:46
12 views 1066999 1247665787 Wed 7/15/2009 13:49
13 views 1077726 1247778752 Thu 7/16/2009 21:12
14 views 1083059 1247845413 Fri 7/17/2009 15:43
15 views 1083059 1247845824 Fri 7/17/2009 18:45
16 views 1089529 1247914194 Sat 7/18/2009 10:49


testdata$date = as.Date(testdata$date,"%m/%d/%Y")

Thudat = subset(testdata,day=="Thu")
Fridat = subset(testdata,day=="Fri")

Friday_dates = Thudat$date+1

Friday_info = NULL

for(i in 1:length(Friday_dates)){

temp = subset(Fridat,date==Friday_dates[i]) # select the Friday dates from
Fridat

if(nrow(temp)>0){ # if that Friday date value exists in Friday

Friday_info = rbind(Friday_info,temp[nrow(temp),]) # by saying nrow(temp)
with the data organized chronologically already, you don't have to add an
additional if      statement for multiple measurements in the same day.

} else { # if that Friday date value doesn't exist in Fridat

Friday_info = rbind(Friday_info,Thudat[i,]) # choosing the date from Thudat
instead.

}

}

Friday_info
   views  number  timestamp day       date  time
7  views 1011144 1247135553 Thu 2009-07-09 10:32
15 views 1083059 1247845824 Fri 2009-07-17 18:45


Also, for other things involving getting data out to monthly or weekly, you
might want to try working with some functions from the chron package.
Things like seq.dates can allow you to get the appropriate dates for a
specific day of the week for every week that you want.  something like this
for instance:

as.Date(seq.dates("7/3/2009","7/24/2009",by="weeks"),"%m/%d/%Y")

for all the Fridays in July 2009.


Hope this helps!

A

-- 
Adrienne Wootten
Graduate Research Assistant
State Climate Office of North Carolina
Department of Marine, Earth and Atmospheric Sciences
North Carolina State University




On Fri, Nov 5, 2010 at 1:22 PM, thornbird <huachang396@gmail.com> wrote:

>
> I am new to Using R for data analysis. I have an incomplete time series
> dataset that is in daily format. I want to extract only Friday data from
> it.
> However, there are two problems with it.
>
> First, if Friday data is missing in that week, I need to extract the data
> of
> the day prior to that Friday (e.g. Thursday).
>
> Second, sometimes there are duplicate Friday data (say Friday morning and
> afternoon), but I only need the latest one (Friday afternoon).
>
> My question is how I can only extract the Friday data and make it a new
> dataset so that I have data for every single week for the convenience of
> data analysis.
>
> Your help and time will be appreciated. Thanks.  Kevin
>
>
> Below is what my dataset looks like:
>
>   views  number  timestamp day            time
> 1  views  910401 1246192687 Sun 6/28/2009 12:38
> 2  views  921537 1246278917 Mon 6/29/2009 12:35
> 3  views  934280 1246365403 Tue 6/30/2009 12:36
> 4  views  986463 1246888699 Mon  7/6/2009 13:58
> 5  views  995002 1246970243 Tue  7/7/2009 12:37
> 6  views 1005211 1247079398 Wed  7/8/2009 18:56
> 7  views 1011144 1247135553 Thu  7/9/2009 10:32
> 8  views 1026765 1247308591 Sat 7/11/2009 10:36
> 9  views 1036856 1247436951 Sun 7/12/2009 22:15
> 10 views 1040909 1247481564 Mon 7/13/2009 10:39
> 11 views 1057337 1247568387 Tue 7/14/2009 10:46
> 12 views 1066999 1247665787 Wed 7/15/2009 13:49
> 13 views 1077726 1247778752 Thu 7/16/2009 21:12
> 14 views 1083059 1247845413 Fri 7/17/2009 15:43
> 15 views 1083059 1247845824 Fri 7/17/2009 18:45
> 16 views 1089529 1247914194 Sat 7/18/2009 10:49
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/How-to-extract-Friday-data-from-daily-data-tp3029050p3029050.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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.
>

	[[alternative HTML version deleted]]

