Error in ** : incorrect number of dimensions

本文探讨了一维向量在试图使用二维索引时出现的 'incorrectnumberofdimensions' 错误。作者通过实例展示了如何正确地处理一维向量的索引,避免这种维度不一致的问题,适合初学者理解向量操作的规范。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Error in ** : incorrect number of dimensions

目录

Error in ** : incorrect number of dimensions

问题:

解决:

完整错误:


问题:

#向量是一维的,尝试使用二维数据集来进行索引,当然不行;

#

#define vector
x <- c(3, 4, 7, 7, 14, 19, 22, 28, 29, 30)

#attempt to access value in first row and third column
x[ , 3]

#attempt to access value in third row and first column
x[3, ]

解决:

#按照一维的方式来索引

#access third value in vector
x[3]

#access values in positions 2 through 5
x[2:5]

完整错误:

> #define vector
> x <- c(3, 4, 7, 7, 14, 19, 22, 28, 29, 30)

> #attempt to access value in first row and third column
> x[ , 3]
Error in x[, 3] : incorrect number of dimensions

> #attempt to access value in third row and first column
> x[3, ]
Error in x[3, ] : incorrect number of dimensions

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Data+Science+Insight

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值