Thanks to everyone for their help so far. It's been greatly appreciated. I
have a new, but similar problem:
I have data that I have broken down by hour (median/mean for each hour). I
would like to break it down further, by each half hour (0:00-0:29,
0:30-0:59, 1:00-1:29, 1:30-1:59, etc). I thought cut.dates() from the chron
package would be able to do it, but I can't find anything in the chron
package documention. I'm fairly certain that if I can figure out how to
break down the data by half hour that I can do all the other analysis just
fine (median/mean for each half hour, etc)
Here is a small sample of the data:
Hello,
You can use cut.POSIXt from package base.
cut(dat$SunDate, breaks="30 mins")
Hope this helps,
Rui Barradas
Em 10-07-2012 13:43, APOCooter escreveu:
Thanks to everyone for their help so far. It's been greatly appreciated. I
have a new, but similar problem:
I have data that I have broken down by hour (median/mean for each hour). I
would like to break it down further, by each half hour (0:00-0:29,
0:30-0:59, 1:00-1:29, 1:30-1:59, etc). I thought cut.dates() from the chron
package would be able to do it, but I can't find anything in the chron
package documention. I'm fairly certain that if I can figure out how to
break down the data by half hour that I can do all the other analysis just
fine (median/mean for each half hour, etc)
Here is a small sample of the data:
Hmm, I guess that's not exactly what I needed. It's my fault; you gave me
what I asked for, I was just asking for the wrong thing.
What I'm hoping to do is something similar to:
aggregate(dat$SunScore, by=list(h), median)
except I'd like to do it by half hour instead of hour. I guess what I need
is a function similar to the hours() function. I only have rudimentary
programming knowledge, but here's a stab at it, mostly in psuedo-code:
#time is the number I'm looking for, which represents the half hour
0:00-0:29=0, 0:30-0:59=.5, 1:00-1:29=1, 1:30-1:59=1.5, etc
time=0
h<-hours(x)
m<-minutes(x)
if(m<30)
then time=h
else
time=h + 0.5
Will this, if programmed correctly, give me an output similar to the hours()
output so that I can use the aggregate() function?
Thanks,
Mike
Rui Barradas wrote
Hello,
You can use cut.POSIXt from package base.
cut(dat$SunDate, breaks="30 mins")
Hope this helps,
Rui Barradas
Em 10-07-2012 13:43, APOCooter escreveu:
Thanks to everyone for their help so far. It's been greatly appreciated.
I
have a new, but similar problem:
I have data that I have broken down by hour (median/mean for each hour).
I
would like to break it down further, by each half hour (0:00-0:29,
0:30-0:59, 1:00-1:29, 1:30-1:59, etc). I thought cut.dates() from the
chron
package would be able to do it, but I can't find anything in the chron
package documention. I'm fairly certain that if I can figure out how to
break down the data by half hour that I can do all the other analysis
just
fine (median/mean for each half hour, etc)
Here is a small sample of the data:
Hello,
If I understanding it, what you want are the values below.
half.hours <- function(x){
s <- strsplit(as.character(x), ":")
H <- as.integer(sapply(s, `[`, 1))
M <- as.integer(sapply(s, `[`, 2))
h <- (H*60 + M)/60
floor(h/0.5)*0.5
}
half.hours(dat$SunTime)
And this can be used in aggregate.
half.hr <- half.hours(dat$SunTime)
aggregate(SunScore ~ half.hr, data = dat, mean)
Rui Barradas
Em 11-07-2012 14:33, APOCooter escreveu:
Hmm, I guess that's not exactly what I needed. It's my fault; you gave me
what I asked for, I was just asking for the wrong thing.
What I'm hoping to do is something similar to:
aggregate(dat$SunScore, by=list(h), median)
except I'd like to do it by half hour instead of hour. I guess what I need
is a function similar to the hours() function. I only have rudimentary
programming knowledge, but here's a stab at it, mostly in psuedo-code:
#time is the number I'm looking for, which represents the half hour
0:00-0:29=0, 0:30-0:59=.5, 1:00-1:29=1, 1:30-1:59=1.5, etc
time=0
h<-hours(x)
m<-minutes(x)
if(m<30)
then time=h
else
time=h + 0.5
Will this, if programmed correctly, give me an output similar to the hours()
output so that I can use the aggregate() function?
Thanks,
Mike
Rui Barradas wrote
Hello,
You can use cut.POSIXt from package base.
cut(dat$SunDate, breaks="30 mins")
Hope this helps,
Rui Barradas
Em 10-07-2012 13:43, APOCooter escreveu:
Thanks to everyone for their help so far. It's been greatly appreciated.
I
have a new, but similar problem:
I have data that I have broken down by hour (median/mean for each hour).
I
would like to break it down further, by each half hour (0:00-0:29,
0:30-0:59, 1:00-1:29, 1:30-1:59, etc). I thought cut.dates() from the
chron
package would be able to do it, but I can't find anything in the chron
package documention. I'm fairly certain that if I can figure out how to
break down the data by half hour that I can do all the other analysis
just
fine (median/mean for each half hour, etc)
Here is a small sample of the data: