r - 如何在R中比较两个变量列?
问题描述
我是 R 新手,需要帮助!我有很多变量,包括 Response 和 RightResponse。我需要比较这两列,并创建一个新列来显示每个值对之间是否存在匹配或缺失。谢谢。
解决方案
也许是这样的?
library(magrittr)
library(dplyr)
> res <- data.frame(Response=c(1,4,4,3,3,6,3),RightResponse=c(1,2,4,3,3,6,5))
> res <- res %>% mutate("CorrectOrNot" = ifelse(Response == RightResponse, "Correct","Incorrect"))
> res
Response RightResponse CorrectOrNot
1 1 1 Correct
2 4 2 Incorrect
3 4 4 Correct
4 3 3 Correct
5 3 3 Correct
6 6 6 Correct
7 3 5 Incorrect
基本上,mutate 函数创建了一个新列,其中包含 Response 和 RightResponse 之间的比较结果。
希望这可以帮助!
推荐阅读
- angular - 无法为通过扩展运算符添加的两个新属性同时导出两个计算值
- r - 将 Tibble 字符列转换为日期列的问题
- java - 如何将 appcompactactivity 更改为片段
- html - 多行表格中的一张图片
- javascript - 等待 asyncIterator 生成器函数中的异步操作
- reactjs - 有没有办法在 Material UI 的 Box(es) 内添加自定义分辨率?
- amazon-web-services - 使用任何方法时的 AWS API Gateway HTTP API CORS 问题
- mapping - 在 ADF 映射中将日期时间转换为日期?
- java - 创建日志文件而不在控制台中看到它们。爪哇
- javascript - jquery-ui.js:8056 未捕获类型错误:无法读取未定义的属性“左侧”