Home > Blockchain >  How to get count of data types in a data frame in R studio?
How to get count of data types in a data frame in R studio?

Time:01-30

i need to get count of data types of the data which has 4 columns of data in R studio??

i.e., numeric = 2 and factor = 1 . Like this

CodePudding user response:

Is this what you had in mind?

data(iris)
table(sapply(iris, class))
#> 
#>  factor numeric 
#>       1       4

CodePudding user response:

jrcalabrese's answer satisfies the question perfectly. As is the case with many tasks, there is probably a package for it. For such question the skimr package provides some nice tools:

skimr::skim(iris)

-- Data Summary ------------------------
                           Values
Name                       iris  
Number of rows             150   
Number of columns          5     
_______________________          
Column type frequency:           
  factor                   1     
  numeric                  4     
________________________         
Group variables            None  

-- Variable type: factor ----------------------------------------------------------------------
# A tibble: 1 x 6
  skim_variable n_missing complete_rate ordered n_unique top_counts               
* <chr>             <int>         <dbl> <lgl>      <int> <chr>                    
1 Species               0             1 FALSE          3 set: 50, ver: 50, vir: 50

-- Variable type: numeric ---------------------------------------------------------------------
# A tibble: 4 x 11
  skim_variable n_missing complete_rate  mean    sd    p0   p25   p50   p75  p100 hist 
* <chr>             <int>         <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
1 Sepal.Length          0             1  5.84 0.828   4.3   5.1  5.8    6.4   7.9 ▆▇▇▅▂
2 Sepal.Width           0             1  3.06 0.436   2     2.8  3      3.3   4.4 ▁▆▇▂▁
3 Petal.Length          0             1  3.76 1.77    1     1.6  4.35   5.1   6.9 ▇▁▆▇▂
4 Petal.Width           0             1  1.20 0.762   0.1   0.3  1.3    1.8   2.5 ▇▁▇▅▃
  •  Tags:  
  • Related