Hello to everyone! I'm a new to R and I don't succed in updating a variable (SR) in a for loop. The script created is the following one: path=c("C:/Users/memeo/Documents/Dottorato/soggetti visus danneggiato/") subjects=list.files(path) # subjects=subjects[c(1:35,37)] n_gradini=rep(c(1,2,4),length(subjects)) allsubjects=c(rep(subjects,each=3)) for (i in length(subjects)) { path_each_subj=paste0(path,subjects[i]) no_thumbs<-grep("Thumbs",subjects) n=1:length(subjects) clear_thumbs=n!=no_thumbs if(clear_thumbs[i]) { each_subject=list.files(path_each_subj) find_gradini<-grep("gradini",each_subject) file_gradini=each_subject[find_gradini] path_file_gradini=paste0(path_each_subj,"/",file_gradini) SR<-(rep(0,3)) # SR<-matrix(data=NA,nrow=36*3,ncol=1) for(j in length(path_file_gradini)) { gradini<-read.table(file=path_file_gradini[j],header=T,quote="\"",skip=1) data<-data.frame(gradini) names(data)=c("Id","Time","X","Y","H","Sound") #Calculate derivatives for isolate the positive contributes Hdiff=diff(data$H) Height=Hdiff[Hdiff>0] SR[j]<-length(Height)/tSR } blind=data.frame(Names=allsubjects,Gradini=n_gradini,StimuliRate=SR) print(SR) } else i=i+1 } write.table(blind,file="10Blind",sep=" ", eol="\r\n") CAN ANYONE HELP ME? Thank you very much! -- *M. Memeo* [[alternative HTML version deleted]]