【发布时间】:2020-07-30 23:37:06
【问题描述】:
我正在关注this data cleaning instruction,但截至this line(如下所示),我收到以下错误:Error: Problem with mutate() input l5cathol。
我错过了什么吗?
library(tidyverse)
library(haven)
library(sjmisc)
library(googledrive)
googledrive::drive_download('https://drive.google.com/file/d/124WOY4iBXxv_9eBXsoHJVUzX98x2sxYy/view?usp=sharing','test.por',overwrite=T)
dta <- haven::read_por('test.por')
names(dta) <- tolower(names(dta))
# Convert variables of interest to character/numeric
vars_chrs <- c("childid","l5cathol","l5public","r5race","w3povrty","w3daded","w3momed","w3inccat","p5fstamp")
vars_nums <- c("w3momscr", "w3dadscr","p5numpla","p5hmage","p5hdage","c5r2mtsc")
dta <- dta %>%
mutate_at(vars(one_of(vars_chrs)), funs(as.character(to_label(.)))) %>% ##** @@ HERE throws error !!!
mutate_at(vars(one_of(vars_nums)), funs(as.numeric(as.character(to_label(.)))))
【问题讨论】:
-
你能用dput显示数据行吗
-
我是通过下载得到的。这是一个大数据
-
请检查所有列是否存在
lapply(dta[1:3, vars_chrs], function(x) as.character(to_label(x))) -
即我得到的列名是大写的
colnames(dta) %>% head [1] "CHILDID" "PARENTID" "S5_ST_ID" "S5_ID" "T5_ID" "D5T_ID"