select all the col in df exept the last in r

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.r
library(dplyr)

new_df <- df %>% 
  select(-ncol(df))
54 chars
5 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