I have vector from which I've created subset using this command:
sub.as = as[seq(70,100)]
The subset is following:
> is.vector(sub.as)
[1] TRUE
> str(sub.as)
num [1:31] 1 0.75 0.9 0.475 0.925 0.975 1 1 0.525 1 ...
> sub.as
[1] 1.000 0.750 0.900 0.475 0.925 0.975 1.000 1.000 0.525 1.000 0.200 0.200
[13] 0.200 0.200 0.150 0.150 0.150 0.150 0.150 0.450 0.875 0.175 0.150 0.150
[25] 0.150 0.100 0.100 0.100 0.100 0.350 1.000
I've applied rollapply
to this vector following way:
> sub.as.avg.1 = rollapply(sub.as, width = 1, by = 1, FUN = mean, align = "left")
Based on this answer I've compared both vectors. Length of the outputs are the same:
> length(sub.as)
[1] 31
> length(sub.as.avg.1)
[1] 31
Values on those indexes should be different:
> which(sub.as != sub.as.avg.1)
[1] 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29
Values that should be different (but as you can see they aren't):
> sub.as[which(sub.as != sub.as.avg.1)]
[1] 0.200 0.200 0.200 0.200 0.150 0.150 0.150 0.150 0.150 0.450 0.175 0.150
[13] 0.150 0.150 0.100 0.100 0.100 0.100
> sub.as.avg.1[which(sub.as != sub.as.avg.1)]
[1] 0.200 0.200 0.200 0.200 0.150 0.150 0.150 0.150 0.150 0.450 0.175 0.150
[13] 0.150 0.150 0.100 0.100 0.100 0.100
Questions:
- is
vec
same asrollapply(vec, width = 1, by = 1, FUN = mean, align = "left")
? - Why
which
shows that there are differences between vectors?