[R] Error:'subscript out of bounds'

Samsad Afrin Himi samsad.afrin at gmail.com
Tue Jul 12 15:29:35 CEST 2016


Dear R-team,

I have written this code for calculation my data file. But there shows 'subscript out of bounds’.



> computeResponse <- function(data){
+     dataodd <- data[-(1:18),]
+     dataodd <- dataodd[seq(1,nrow(dataodd), 2),]
+     hitsodd <- table(factor(dataodd[,5]), factor(dataodd[,15]))[2,2]
+     missesodd <- table(factor(dataodd[,5]), factor(dataodd[,15]))[2,1]
+     crejectionsodd <- table(factor(dataodd[,5]), factor(dataodd[,15]))[1,2]
+     falsealarmodd <- table(factor(dataodd[,5]), factor(dataodd[,15]))[1,1]
+     return(coordinationodd <- data.frame(hitsodd, missesodd,crejectionsodd, falsealarmodd))
+ }
> 
> filenames <- list.files(full.names=TRUE)
> filelist <- lapply(filenames, read.table, fill = TRUE, header = FALSE, sep = "\t")
> coordinationodd <- lapply(filelist, computeResponse)
Error in table(factor(dataodd[, 5]), factor(dataodd[, 15]))[2, 2] : 
  subscript out of bounds
> coordinationodd <- Reduce(rbind, coordinationodd)
Error in Reduce(rbind, coordinationodd) : 
  object 'coordinationodd' not found


Could you please tell me how I can fix this problem?

Best,
Samsad
	[[alternative HTML version deleted]]



More information about the R-help mailing list