Error in **: incorrect number of subscripts on matrix

目录

Error in **: incorrect number of subscripts on matrix

问题:

解决:

完整错误:


问题:

赋值的时候添加了逗号;

俗话说到什么山唱什么歌,R不吃这一套,他不是python(numpy)、也不是java、不是pascal、、、、

#define vector
x <- c(4, 6, 7, 7, 15)


#attempt to assign the value '22' to element in third position
x[3, ] <- 22

解决:

#按照位置赋值

assign the value '22' to element in third position
x[3] <- 22

#display updated vector
x

[1]  4  6 22  7 15

#for循环按照位置赋值

#define vector
x <- c(4, 6, 7, 7, 15)

#replace every value in vector with zero
for(i in 1:length(x)) {
    x[i]=0
  }

#view updated vector
x

[1] 0 0 0 0 0

完整错误:

> #define vector
> x <- c(4, 6, 7, 7, 15)


> #attempt to assign the value '22' to element in third position
> x[3, ] <- 22
Error in x[3, ] <- 22 : incorrect number of subscripts on matrix

Logo

GitCode AI社区是一款由 GitCode 团队打造的智能助手,AI大模型社区、提供国内外头部大模型及数据集服务。

更多推荐