R: dplyr - error when using the transcode function

I am new to R and trying to translate ordinal variables into numerical values. I have a variable named "Founders_previous_company_employee_count" that has 3 different entries as inputs - ("Small", "Medium", "Large"), which I write to 1,2,3 values ​​respectively. I tried using the realue function from the plyr package using the code below

startupfull$employee_count_code<-as.numeric(revalue(startupfull$Founders_previous_company_employee_count,c("Small"=1, "Medium"=2, "Large"=3))) 

which works great. However, I am trying to use the recode function in the dplyr package, I am getting an error.

The code:

startupfull$prevcomp_empcount_code <-  as.numeric(recode(startupfull$Founders_previous_company_employee_count,c("Small"=1, "Medium"=2, "Large"=3)))

Error - error: all replacements must be named

What am I doing wrong here?

+4
source share
3 answers

Aramis7d , .

, - (, ), , , , as.numeric() factor(), joel.wilson, , , c() dplyr recode().

:

    startupfull$prevcomp_empcount_code <-  
    as.numeric(recode(startupfull$Founders_previous_company_employee_count,
                    c("Small"=1, "Medium"=2, "Large"=3)))

:

    startupfull$prevcomp_empcount_code <- 
    as.numeric(recode(startupfull$Founders_previous_company_employee_count,
                      "Small"=1, "Medium"=2, "Large"=3))
+2

dput(x)

c("Small", "Large", "Medium", "Large")

as.numeric(recode(x, "Small" = "1", "Medium" = "2", "Large" = "3"))
+1
x = c("Small", "Large", "Medium", "Large")
as.numeric(factor(x, levels = c("Small", "Medium", "Large")))
[1] 1 3 2 3
0
source

Source: https://habr.com/ru/post/1660662/


All Articles