I'm relatively new to programming, and have found the following link incredibly helpful in trying to create new variables from a large dataset using a loop: Change variable name in for loop using R i.e.
for (i in 1:13){
assign(paste("conD",i, sep=""), (subset(con,day==i)))
}
This is to produce a set of 13 variables from a dataset of control biological samples, with each subset containing data from each day in the timeseries day1-day13 i.e. "conD1" would contain data from controls analysed on day 1. (the dimensions of the df are generally 3x4000). This worked perfectly. However, I now wish to create 13 more variables in a loop, with the median of each column calculated, i.e. "medconD1" - "medconD13" within a loop, each one 1x4000, by recalling the created variables conD1-conD13. I have tried the following code, but this doesnt work:
for (i in 1:13){
assign(paste("medconD",i, sep=""), (apply(conD[i][8:n], 2, FUN = median)))
}
Can anyone help or point out where I am going wrong here? How do I recall the conD[i] variables in this second part of code? This will save me weeks of work with large datasets! Thank you