Summing specific data from column in r
Im trying to creat a function in r that will let me sum data from the last
three rows into a new column (i.e. if im looking at day 4 = days 3+2+1)
This is what i've worked out so far, however it doesnt work.
S3<- function(x){
res <- numeric(nrow(x))
for (i in 1:nrow(x)){
res[i] <- i
if (i > 3) {
res[i] <- x[i-3,10]
} else {
res[i] <- x[i,10]
}
}
x$PP3 <- res
return(x)
}
No comments:
Post a Comment