0

so I've been trying to implement this action for ages now and some or the other error keeps coming; in the beginning it was error -

no applicable method for "select_" applied to an object of class 'character' and now it's unknown column 'prime_code'.

Here's my 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)

Can someone tell me what's wrong?

Badro Niaimi
  • 959
  • 1
  • 14
  • 28
  • Pleasse check the `colnames(dat_r)` – akrun Dec 02 '19 at 21:43
  • 3
    What version of `dplyr` do you have installed? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Dec 02 '19 at 21:43
  • 3
    Also, it probably should be `recode(prime_code, "1"= "professor", "0"="hooligan")` The quotes seem to be in the wrong places. And don't repeat the `dat_r` in the `mutate()` if you are piping the data in from the previous `select()` – MrFlick Dec 02 '19 at 21:45

1 Answers1

0

Assuming this is how your data looks like, this should work. Ideally it is better to share your answer given a reproducible example.

The main issues in the code are with a wrongly placed double quotation in the recode function and you do not need language$dat_r in the filter key word.

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")
Nareman Darwish
  • 1,251
  • 7
  • 14