To drop variables from a data frame in R, you can use the select()
function from the dplyr
package. select()
is used to filter the columns of a data frame based on their names. You can use the -
sign to exclude specific columns from the selection.
Here's an example:
main.r206 chars15 lines
In this example, we use select()
to drop the b
column from the df
data frame. The resulting data frame df_new
only contains the a
and c
columns.
You can also use the select()
function to keep only specific columns, by listing their names inside the function call. For example:
main.r63 chars3 lines
This will create a new data frame with only the a
and c
columns from the original data frame.
gistlibby LogSnag