I have two data frames 'obs' and 'sim' each with 25 columns. I want to do the following operation using for- loop
for(i in 2:25) {
obs<-obs[,i]
sim<-sim[,i]
plot(sim,obs)
}
But it gives an error 'Error in obs[, i] : incorrect number of dimensions'. I am sure both data frames are Matrix. And when I do without the loop it works (eg: obs[,2], obs[,3], and so on). I don't know what's wrong with the loop. Anyone to help?
In that loop you are changing the size of
obs
on every single iteration to a one dimensional object at this line:So now
obs
is just the 'ith' column ofobs
and then on your second iteration your loop barfs.