Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我想将 csv 文件中的一列数据与一个值进行比较,我需要做什么?我的任务将是:我有一列数据:
number 1 -2 2 0 3 3 4 -1 5 1
我想将每个数字与 0 进行比较,如果数字 > 0;然后积极=+。另一方面,如果数字 < 0;然后是负++。如果数字 == 0; 然后是中性++。
最后它将返回总正数 = X,负数 = Y 和中性 = Z。
这个问题的 R 代码是什么?
看看这是否有效
test <- data.frame(number = c(-2,0,3,-1,1)) test$logic <- ifelse(test$number>0, "positive", ifelse(test$number==0, "neutral", "negative")) data.frame(table(test$logic))