I have a data structure created using read.csv() of dimensions 130, 395. I am trying to iterate over the data by row and return a vector containing a list of lists of the sum over each row in increments of 5 (only from data[,13:395]). I have written the following code, but it returns a vector with sums over intervals of 5 by column and it is also an infinite loop. In other words, I am trying to figure how to make this code finite and work by row.
data <- read.csv(file = "Table.csv")
indexes <- c(13:395)
counter <- 0
a <- c()
list <- c()
for(line in data){
for(index in indexes){
while(counter<5){
a <- c(a, line[index])
counter = counter + 1
}
list <- c(list, sum(a, na.rm = TRUE))
counter = 0
a = c()
}
}
Thanks for your help
How about this?
For your purposes, you’d only pass columns
13:365(i.e. something liked[,13:365]instead of justd).I see now that I used
meaninstead ofsumby mistake, but that change is easy to make.