I am trying to split a column of numerical data by allocating every 12 consecutive values (non-repetitive) into a new (shorter) column. Any help would be greatly appreciated.
So far I tried:
df_all <- rnorm(500, mean = 5, sd = 1) # example data, I didnt use this one
df_final <- matrix(, nrow = 12, ncol = 0)
for(i in seq(1, length(df_all), 12)) {
x <- df_all[i:i+11]
df_final <- data.frame(cbind(df_final, x))
}
write.csv(df_final, file = paste0(rootdir,"/","mT",'.csv'))
It doesnt work, it is appending the same 12th values of segment "x" to all 12 rows of the new column. I checked df_all[1:12] and it is returning normal correct values.