If i have multiple csv files stored as: m1.csv, m2.csv,.....,m50.csv and what I would like to do is load each csv into R, run the data in the i-th file and store it as a variable: m'i'. I am trying to use a for loop but i'm not sure if i can quite use them in such a way. For example:
for (i in 1:100){
A<-as.matrix(read.csv("c:/Users/Desktop/m"i".csv))
...
#some analysis on A
...
m"i"<- #result of analysis on A
}
V<-cbind(m1,m2, .... ,m100)
paste0to assemble paths and names, and probablyassigninstead of<-, as your name will be quoted, but yes, the approach is pretty common. You won't want to do analysis in the loop, though; save that for later. You may also want to save them into a list—instead of the global environment—to make looping over them later easier. It also simplifies naming.assignis almost never a good idea. A simplelapplywould solve OP's task in a cleaner way.