| lookfor {questionr} | R Documentation |
lookfor emulates the lookfor Stata command in R. It supports
searching into the variable names of regular R data frames as well as into
SPSS and Stata datasets loaded in R via the haven,
in which case it will also search variable descriptions (labels).
The command is meant to help users finding variables in large datasets.
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) |
The function looks into the variable names for matches to the keywords. If the data frame has been imported into R with haven package, then variable labels are included in the search scope. If labelled package is installed, variable labels of data.frame imported with foreign or memisc packages will also be taken into account.
a data frame featuring the variable position, name and description (if it exists) in the original data frame
François Briatte <f.briatte@gmail.com>
Based on the behaviour of the lookfor command in Stata.
query in the memisc package
lookfor(iris)
# Look for a single keyword.
lookfor(iris, "petal")
lookfor(iris, "s")
# Look for with a regular expression
lookfor(iris, "petal|species")
lookfor(iris, "s$")
# Look for with several keywords
lookfor(iris, "pet", "sp")
lookfor(iris, "pet", "sp", "width")
# Load memisc package and example data.
## Not run: require(memisc)
nes1948.por <- UnZip("anes/NES1948.ZIP","NES1948.POR", package="memisc")
nes1948 <- spss.portable.file(nes1948.por)
# Look for a vector of keywords.
lookfor(nes1948, c("Truman", "Dewey"))
# Look for a regular expression.
lookfor(nes1948, "truman|dewey")
# Look for a phrase.
lookfor(nes1948, "personal attribute")
## End(Not run)
# Labelled data
data(fecondite)
lookfor(femmes)
lookfor(femmes, "date")
# Display details
lookfor(femmes, details = TRUE)