Error: Can't subset columns that don't exist. x Column `month` doesn't exist

EN: hi, I'm working with this database that I need to modify in order to remove a time variable and add that value to the variable I'm studying. I have the code that SHOULD work, but when running it says that one of my columns doesn't exist, and believe me it does. I checked because I know it's case sensitive, and I just don't know what else to do. If someone could help me, I'd appreciate it a lot!

ES: estoy trabajando con una base de datos y busco reordenarla para eliminar mi variable temporal y añadirlo la variable de estudio. Tengo el código que DEBERÍA funcionar, pero al ejecutarlo con mi base de datos me dice que una de mis columnas no existe, cosa que es imposible porque... la estoy viendo básicamente. Si alguien pudiese ayudarme lo agradecería bastante!

install.packages("ALA", repos="http://R-Forge.R-project.org")
library(ALA)
library(ggplot2)
library(tidyr)
library(dplyr)
library(stringr)

cholest <- ALA::cholesterol

df_chol <- cholest %>% 
  # we'll want to add that `tol` prefix back to the `age` values
  mutate(month = str_c("cholest", month)) %>% 
  # this variable is just in the way. we'll drop it
  select(-month) %>%
  # here's the main action
  pivot_wider(names_from = month, values_from = cholesterol)

HI,

This might be the problem? You deselect your column, so it is not available anymore.

JW

1 Like

Hi Jwvz001. I can't stress enough how much fixing this dumb mistake helped me, so thank you so so much! I don't know why, but when I ran code with that part commented, it kept returning an error, so I thought that may not be the problem, however I just tried again and it worked. So yeah, thanks a lot!!

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.