1
Hello,
I have a database and would like to know which field names through a command in R. What is the best way to proceed? I tried to use describe() but failed.
1
Hello,
I have a database and would like to know which field names through a command in R. What is the best way to proceed? I tried to use describe() but failed.
5
The r-base
offers the options of:
names()
: to know the names of the variables that are in the data frame..str()
: to know the structure of the object in question. In this case data.frame
, this means knowing the amount 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
) is already in the R
(bundle 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 dplyr offers a more elegant 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,...
Browser other questions tagged r dplyr
You are not signed in. Login or sign up in order to post.
If the dataset calls
df
, donames(df)
.– Marcus Nunes
@Marcusnunes Or
str(df)
.– Rui Barradas