Error in *** : subscript out of bounds
目录
Error in *** : subscript out of bounds
问题:
数据越界了啊,除了别介,谁知道那是在哪里?你问内存?内存问谁?
#make this example reproducible
set.seed(0)
#create matrix with 10 rows and 3 columns
x = matrix(data = sample.int(100, 30), nrow = 10, ncol = 3)
#print matrix
print(x)
#attempt to display 11th row of matrix
x[11, ]
#attempt to display 4th column of matrix
x[, 4]
#attempt to display value in 11th row and 4th column
x[11, 4]
解决:
#
#display number of rows and columns in matrix
dim(x)
#
#display 10th row of matrix
x[10, ]
#display number of columns in matrix
ncol(x)
#display 3rd column of matrix
x[, 3]
#display value in 10th row and 3rd column of matrix
x[10, 3]
完整错误:
>
> #attempt to display 11th row of matrix
> x[11, ]
Error in x[11, ] : subscript out of bounds
>
> #attempt to display 4th column of matrix
> x[, 4]
Error in x[, 4] : subscript out of bounds
>
> #attempt to display value in 11th row and 4th column
> x[11, 4]
Error in x[11, 4] : subscript out of bounds
>