gpt4 book ai didi

r - ans[npos] <- rep(no, length.out = len)[npos] 错误 : replacement has length zero

转载 作者:行者123 更新时间:2023-12-04 08:29:26 27 4
gpt4 key购买 nike

您好,我目前是一年级学生,仍在学习 R 在线类(class),我收到一条错误消息:“ans[npos] <- rep(no, length.out = len)[npos] 中的错误:替换的长度为零另外: 警告信息:在 rep(no, length.out = len) : 'x' is NULL so the result will be NULL"in R studio 我不知道为什么这样做,我使用 read.csv 获取数据并获取第二个列,然后取第二列的前两项,然后将第一项与第二列的第三项进行比较,这是我的代码:

dataGrade <- read.csv(file.choose(), fileEncoding = "UTF-8-BOM")

gradeColumn2 <- dataGrade[, 2]
twoGrades <- gradeColumn2[1:2]

ifelse(twoGrades[1] == gradeColumn2[3],
cat("Grade", twoGrades[1],"is equal to Grade",gradeColumn2[3]),
cat("Grade", twoGrades[1],"is not equal to Grade",gradeColumn2[3]))

csv文件中的数据为

enter image description here

最佳答案

因为您正在检查长度为 1 的条件,所以使用 if/else 而不是 ifelse

dataGrade <- data.frame(GRADE.A = c(79, 89, 93),
GRADE.B = c(90, 92, 91))

gradeColumn2 <- dataGrade[, 2]
twoGrades <- gradeColumn2[1:2]

if(twoGrades[1] == gradeColumn2[3]) {
cat("Grade", twoGrades[1],"is equal to Grade",gradeColumn2[3])
} else{
cat("Grade", twoGrades[1],"is not equal to Grade",gradeColumn2[3])
}

#Grade 90 is not equal to Grade 91

关于r - ans[npos] <- rep(no, length.out = len)[npos] 错误 : replacement has length zero,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65101723/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com