Suppose, you have a data.frame like this:
x <- data.frame(v1=1:20,v2=1:20,v3=1:20,v4=letters[1:20])
How would you select only those columns in x that are numeric?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
EDIT: updated to avoid use of ill-advised
sapply.Since a data frame is a list we can use the list-apply functions:
Then standard subsetting
For a more idiomatic modern R I’d now recommend
Less codey, less reflecting R’s particular quirks, and more straightforward, and robust to use on database-back-ended tibbles:
Newer versions of dplyr, also support the following syntax: