Command to describe the data in a table

1

Hello,

I have a database and would like to know the field names through a command in R. What is the best way to proceed? I tried using describe () but with no success.

    
asked by anonymous 13.12.2018 / 19:56

1 answer

5

r-base offers the options of:

  • names() : to know the names of the variables that are in the .
  • str() : to know the structure of the object in question. In the case of data.frame , this means knowing the number of variables it has, the number of observations and the name, type and some values of each variable.
  • The data.frame used in the examples ( sleep ) already comes in R (package datasets ).

    names(sleep)
    [1] "extra" "group" "ID" 
    
    str(sleep)
    'data.frame':   20 obs. of  3 variables:
     $ extra: num  0.7 -1.6 -0.2 -1.2 -0.1 3.4 3.7 0.8 0 2 ...
     $ group: Factor w/ 2 levels "1","2": 1 1 1 1 1 1 1 1 1 1 ...
     $ ID   : Factor w/ 10 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
    

    The offers a more stylish option to str() : glimpse() .

    dplyr::glimpse(sleep)
    Observations: 20
    Variables: 3
    $ extra <dbl> 0.7, -1.6, -0.2, -1.2, -0.1, 3.4, 3.7, 0.8, 0.0, 2.0, ...
    $ group <fct> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, ...
    $ ID    <fct> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8,...
    
        
    13.12.2018 / 20:41