labelled (version 2.2.1)

look_for: Look for keywords variable names and descriptions

Description

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.

Usage

look_for(data, ..., labels = TRUE, ignore.case = TRUE,
  details = FALSE)

lookfor(data, ..., labels = TRUE, ignore.case = TRUE, details = FALSE)

Arguments

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 grep pattern, or a vector of keywords; displays all variables if not specified

labels

whether or not to search variable labels (descriptions); TRUE by default

ignore.case

whether or not to make the keywords case sensitive; TRUE by default (case is ignored during matching)

details

add details about each variable (see examples)

Value

a data frame featuring the variable position, name and description (if it exists) in the original data frame

Details

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.

Examples

Run this code
# NOT RUN {
look_for(iris)
# Look for a single keyword.
look_for(iris, "petal")
look_for(iris, "s")
# Look for with a regular expression
look_for(iris, "petal|species")
look_for(iris, "s$")
# Look for with several keywords
look_for(iris, "pet", "sp")
look_for(iris, "pet", "sp", "width")
# Labelled data
# }
# NOT RUN {
require(questionr)
data(fertility)
look_for(women)
look_for(women, "date")
# Display details
look_for(women, details = TRUE)
# }

Run the code above in your browser using DataLab