R: How to Delete All Columns in a Dataframe Except A Specified Few By String [duplicate]
问题 This question already has answers here : Extracting specific columns from a data frame (10 answers) Closed 3 years ago . I have a data frame in R that consists of around 400 variables (as columns), though I only need 25 of them. While I know how to delete specific columns, because of the impracticality of deleting 375 variables - is there any method in which I could delete all of them, except the specified 25 by using the variable's string name? Thanks. 回答1: Sample example: df <- data.frame(a