
Last chance! 50% off unlimited learning
Sale ends in
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)
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
whether or not to search variable labels (descriptions); TRUE
by default
whether or not to make the keywords case sensitive;
TRUE
by default (case is ignored during matching)
add details about each variable (see examples)
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 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.
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.
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")
# Labelled data
data(fecondite)
lookfor(femmes)
lookfor(femmes, "date")
# Display details
lookfor(femmes, details = TRUE)
Run the code above in your browser using DataLab