Columns NA, etc. don't exist

Hello !

I'm kind of a beginner on Rstudio, and I have this problem :
I have a data wich is the result of mass questionning from an institute (7825 people).

I want to recode variables to change names (for exemple, instead of 1 or 2 on the question about the gender, I want to have man or woman). I have no problem to do it, but then when I want to use it with another function, I get this error message :

Erreur : Can't subset columns that don't exist.
x Columns NA, etc. don't exist.

I join a screen of my code so you can see clearly, and as you can see on it, there is no problem with the function until I use my recoded variables.

Thanks for your time !

You issue appears to be in your last line. Select only the column names, not epic$commune. Pasting code and text is much more useful that pasting screenshots.


Sorry didn't know, here's the code lines. But how do I know the column names ? I'm realy new on code and on R so I don't know much :x

epic$commune <- as.factor(epic$C_MMCOM)
epic$commune <- fct_recode(epic$commune,"Oui"="1","Non"="2","NSP"="9")

epic %>% select(H_MAR_C,epic$commune) %>% table()

When you use <- (your first 2 lines) you need to have the epic$ to identify the data frame. In your last line you use a pipe (%>%) to select columns. The pipe already passes the name of the data frame so your last line should be

epic %>% select(H_MAR_C,commune) %>% table()

You know what the column names are because you created them :slight_smile:

You're a genius, thanks a lot. You gave me the solution, but best you allowed me to understand !

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.