更改变量名称和类型后,readr spec()不会更新

时间:2017-03-16 20:53:39

标签: r readr

我对专有数据进行了一些数据争论,并且在对变量名称或类型进行更改后,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

0 个答案:

没有答案