I have this dataset that I wish to reshape to long format.
In manual approach of reshaping, I do it with this:
census_data <- read.csv(file.choose())
colnames(census_data)[8] <- "CENSUSPOP2010"
census_long <- census_data %>%
gather(Var, Value, -SUMLEV, -REGION, -DIVISION, -STATE, -COUNTY, -STNAME, -CTYNAME) %>%
mutate(Time = sub("[A-Za-z]+", "", Var), Type = sub("[\\_0-9]+", "", Var)) %>%
select(-Var) %>%
spread(Type, Value)
But I wish that the independent vars are quoted, so it is easy to pass it to custom functions, so I had to try to define it like this:
var <- c("SUMLEV", "REGION", "DIVISION", "STATE", "COUNTY", "STNAME", "CTYNAME")
var_enquos <- enquos(var)
census_long <- census_data %>%
gather(Var, Value, -!!!var_enquos) %>%
mutate(Time = sub("[A-Za-z]+", "", Var), Type = sub("[\\_0-9]+", "", Var)) %>%
select(-Var) %>%
spread(Type, Value)
But this produces: Error: Can't use !!! at top level.
Is this approach not possible to do?