Skip to content

Problem with loop

3 messages · Komine, R. Michael Weylandt

#
Hi, 
I try to build a loop difficultly. 
I have in a folder called Matrices several files (.csv) called Mat2002273,
Mat2002274  to Mat2002361. 
I want to calculate for each file the mean of the column called Pixelvalues.
I try this code but as result, I have this message:  Mat2002273 not found
Thank you for your help 




--
View this message in context: http://r.789695.n4.nabble.com/Problem-with-loop-tp4148083p4148083.html
Sent from the R help mailing list archive at Nabble.com.
#
You never create a variable called "Mat2002273" or "Mat2002361" so you
can't ask R to loop over all the values between them.

If I were you, I'd code something like this:

lf <- list.files()

# PUT IN SOME CODE TO REMOVE FILES YOU DON'T WANT TO USE

pv <- vector("numeric", length(lf))

for(i in lf) pv[i] <- mean( read.csv(lf, header = TRUE)[,"Pixelvalues"])

print(pv)

Michael
On Fri, Dec 2, 2011 at 12:15 PM, Komine <momadou at yahoo.fr> wrote:
1 day later