An error from dplyr possibly due to the R version

I'm using R 4.0.0 and Rstudio 1.2.5042 on a windows 64 machine. Version of the packages I'm using are listed next to them below.

I'm deeply wondering WHY I'm getting the following error: Error: Problem with mutate() input ..1?

Is there anyone else getting the same error?

library(dplyr)       # 1.0.0
library(haven)       # 2.3.1
library(sjmisc)      # 2.8.4
library(googledrive) # 1.0.1

dta <- read_por('test.por')

names(dta) <- tolower(names(dta))

 vars_chrs <- c("childid","l5cathol","l5public","r5race","w3povrty","w3daded","w3momed","w3inccat","p5fstamp")

 vars_nums <- c("w3momscr", "w3dadscr","p5numpla","p5hmage","p5hdage","c5r2mtsc")

dta %>% 
  mutate(across(vars_chrs, ~ as.character(to_label(.))),   ## ANYONE GETTING ERROR HERE??
  across(vars_nums, ~ as.numeric(as.character(to_label(.)))))

I tried your code and also ran into the same problem. The rest of the error message says:

x Can't subset columns that don't exist.
x Columns `childid`, `l5cathol`, `l5public`, `r5race`, `w3povrty`, etc. don't exist.

so I checked by using

vars_chrs %in% names(dta)

It appears the column names are all caps so you can change the vars_chrs and vars_nums with toupper(). I got the following to work, but I do not have the function to_label() in the packages provided. Additionally, across requires a .x in the function and not simply a .

dta %>% 
  mutate(across(toupper(vars_chrs), ~ as.character(.x)),  
         across(toupper(vars_nums), ~ as.numeric(as.character(.x))))

Thank you. Something is still puzzling me. I'm following this tutorial using the exact same data and code as shown HERE.

At the end of the data cleaning process, as shown HERE, I should get a .csv file named ecls.csv but I get basically nothing.

Are you facing the same problem when you run this whole block of code?

Yes I get a 0 row table after the first filter:

dta <- dta %>%
  filter(l5cathol == 'YES' | l5public == 'YES') %>%
  mutate(catholic = if_else(l5cathol == 'YES', 1, 0))

because the values of l5catholic are:


  -1   -9    1    2 
9714 1587 1516  824 

It appears the structure of the data may have changed since the tutorial was created.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.