我正在对专有数据进行一些数据争论,并且在spec()
更改变量名称或类型后遇到不更新的问题。我将使用mtcars
我正在经历的一个例子。谁能让我知道为什么会这样以及如何让它更新?
library(tidyverse)
# use read_csv to read in original file
mtcars_orig <- read_csv(readr_example("mtcars.csv"))
spec(mtcars_orig) # check variable types
# make work file
mtcars_work <- mtcars_orig
# rename mpg variable
mtcars_work <- rename(mtcars_work, m_p_g = mpg)
str(mtcars_work) # m_p_g name updates
spec(mtcars_work) # mpg name doesn't update
# change cyl to character type
mtcars_work$cyl <- as.character(mtcars_work$cyl)
str(mtcars_work$cyl) # variable type updates
spec(mtcars_work) # variable type doesn't update