r检查整列的值是否大于STH

发布于 2025-02-13 22:34:19 字数 270 浏览 2 评论 0原文

我有一个年龄的专栏,我需要指定年龄以上还是低于某个水平。我还有2列具有因子值t或f(value.if.age.under.13和value.if.age.over.13)。我的代码始终运行其他语句。

for (i in nrow(dclas)){    
  if (dclas[i,6]<13.0){
      x = value.if.age.under.13
  } else{
      x = value.if.age.over.13
  }
}

I have a column where is age and I need to specify whether the age is above or below some level. I also have 2 columns with factor values T or F (value.if.age.under.13 and value.if.age.over.13). My code is always running the else statement.

for (i in nrow(dclas)){    
  if (dclas[i,6]<13.0){
      x = value.if.age.under.13
  } else{
      x = value.if.age.over.13
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你爱我像她 2025-02-20 22:34:19

已经用辅助变量解决了。

help1 = rep(NA, nrow(dclas))
help1 = (dclas[,6] < 13.0) 

df1 = data.frame(value.if.age.under.13, help)
df1$isCorrect = df1[,1] == df1[,2] & df1[,1] == T

如果年龄超过13岁,并且最后连接在一起。

correctVal = rep(NA, nrow(dclas))
correctVal = (df1$isCorrect == help1 & df1$isCorrect == T) | (df2$isCorrect == help2 & df2$isCorrect == T)

Already solved with auxiliary variable.

help1 = rep(NA, nrow(dclas))
help1 = (dclas[,6] < 13.0) 

df1 = data.frame(value.if.age.under.13, help)
df1$isCorrect = df1[,1] == df1[,2] & df1[,1] == T

The same if age is over 13. And at the end connect both.

correctVal = rep(NA, nrow(dclas))
correctVal = (df1$isCorrect == help1 & df1$isCorrect == T) | (df2$isCorrect == help2 & df2$isCorrect == T)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文