look_for emulates the lookfor Stata command in R. It supports
searching into the variable names of regular R data frames as well as into
variable labels descriptions.
The command is meant to help users finding variables in large datasets.
look_for(data, ..., labels = TRUE, ignore.case = TRUE, details = FALSE) lookfor(data, ..., labels = TRUE, ignore.case = TRUE, details = FALSE)
| data | a data frame |
|---|---|
| ... | list of keywords, a character string (or several character strings), which can be formatted as a regular expression suitable for a |
| labels | whether or not to search variable labels (descriptions); |
| ignore.case | whether or not to make the keywords case sensitive;
|
| details | add details about each variable (see examples) |
Based on the behaviour of the lookfor command in Stata.
a data frame featuring the variable position, name and description (if it exists) in the original data frame
The function looks into the variable names for matches to the keywords. If available,
variable labels are included in the search scope.
Variable labels of data.frame imported with foreign or
memisc packages will also be taken into account (see to_labelled).
look_for and lookfor are equivalent.
look_for(iris)#> variable #> 1 Sepal.Length #> 2 Sepal.Width #> 3 Petal.Length #> 4 Petal.Width #> 5 Species# Look for a single keyword. look_for(iris, "petal")#> variable #> 3 Petal.Length #> 4 Petal.Widthlook_for(iris, "s")#> variable #> 1 Sepal.Length #> 2 Sepal.Width #> 5 Species# Look for with a regular expression look_for(iris, "petal|species")#> variable #> 3 Petal.Length #> 4 Petal.Width #> 5 Specieslook_for(iris, "s$")#> variable #> 5 Species# Look for with several keywords look_for(iris, "pet", "sp")#> variable #> 3 Petal.Length #> 4 Petal.Width #> 5 Specieslook_for(iris, "pet", "sp", "width")#> variable #> 2 Sepal.Width #> 3 Petal.Length #> 4 Petal.Width #> 5 Species# Labelled data# NOT RUN { require(questionr) data(fertility) look_for(women) look_for(women, "date") # Display details look_for(women, details = TRUE) # }