I have a vector Z<-c(0, 0, 0, 0, 360, 0, 0, 0, 0) of a daily duration of events (each element of the vector is a day and the value of each element is the episode duration in minutes) so that each element of the vector is [0,1440].
I would like to convert the vector from daily minutes to 1 minute intervals (so that each element of the vector is a 1 minute interval) and the value of each element would be [0,1]. I came up with the following solution
Z<-c(0, 0, 0, 0, 360, 0, 0, 0, 0)
c.Z<-1440- Z
temp<-NULL
for (i in 1:length(Z)){
temp<-c(temp, c(rep(1,Z[i]), rep(0,c.Z[i])))
}
temp
> sum(temp)==sum (Z)
[1] TRUE
> length(temp)==1440*length(Z)
[1] TRUE
Is there a faster, nicer or quicker way to do this without the for function?