To select all the columns in a dataframe except the last one, you can use the select()
function from the dplyr
package in R. Here's how you can do it:
main.r54 chars5 lines
This code uses the %>%
operator to pipe the df
dataframe into the select()
function. The -ncol(df)
argument tells select()
to exclude the column at the last position. The resulting dataframe new_df
will contain all columns of df
except the last.
gistlibby LogSnag