extract numeric variables of a data.frame

Good evening, I have a somewhat trivial question but I'm a beginner ...
How do I build a new data.frame which contains only the numeric variables of another data ??

Moving this from rstudio-cloud to General, since the question does not seem specific to RStudio Cloud.

That could mean a few different things, could you clarify what you're trying to do. (Note the gold standard for asking coding question online is with a reproducible example.. Asking your question with this would help you make clear the question you are posing, and make it easier for folks to offer suggestions to achieve your result you're looking for)

In a data.frame in R, you can think of it as a table with a number of rows and columns. Rows are often referred to as observations. And columns as "variables". Variables are of the same type, for example a column of weights would be either an integer column or a numeric (float), but a column might also have characters strings, or factors.
There's a nice discussion of this here r - Selecting only numeric columns from a data frame - Stack Overflow

For a tidyverse solution, I like

df <- data.frame(v1=1:5,v2=1:5,v3=letters[1:5])
dplyr::select_if(df, is.numeric)
#>   v1 v2
#> 1  1  1
#> 2  2  2
#> 3  3  3
#> 4  4  4
#> 5  5  5

Created on 2021-04-07 by the reprex package (v2.0.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.