所以我很久以来一直在尝试执行此操作,并且某些或其他错误不断出现;一开始是错误-
没有适用于“ select_”的适用于类对象的方法 “字符”,现在是未知列“ prime_code”。
这是我的代码:
dat_r_rdc <- dplyr::select(as.data.frame(dat_r), "prime_code", "language", "country", "correct_pct") %>%
dplyr::mutate(dat_r, condition = recode("prime_code", "1"= professor, "0"=hooligan)) %>%
dplyr::filter(language$dat_r, English)
有人可以告诉我怎么了吗?
答案 0 :(得分:0)
假设您的数据是这样,这应该可以工作。 理想情况下,最好给出一个可重复的示例来分享您的答案。
代码中的主要问题是recode函数中的双引号放置错误,并且过滤关键字中不需要language $ dat_r。
library(dplyr)
prime_code = c("1", "0", "0", "1", "0", "1")
language = c("English", "Arabic", "French", "English", "English", "French")
country = c("US", "UAE", "France", "UK", "Australia", "Nigeria")
correct_pct = c(1, 0, 1, 0, 1, 0)
dat_r <- data.frame(prime_code, language, country, correct_pct, stringsAsFactors = FALSE)
dat_r_rdc <-
as.data.frame(dat_r) %>%
select(prime_code, language, country, correct_pct) %>%
mutate(condition = recode("prime_code", "1" = "professor", "0" = "hooligan")) %>%
filter(language == "English")