Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8662301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:42:08+00:00 2026-06-12T16:42:08+00:00

In Stata the lookfor command offers a quick way to search for variables in

  • 0

In Stata the lookfor command offers a quick way to search for variables in a dataset (and it searches both the variable names and labels). So lookfor education quickly finds you variables related to education. Is there an equivalent shortcut function in R?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:42:09+00:00Added an answer on June 12, 2026 at 4:42 pm

    You can simply grep the data.frame for the information necessary. Then you’ll get much more information than simply the list of names of variables for which somebody is matched. You can also use regular expressions, thus enhancing your search capabilities. Here is the example of a function which does what you want (works with data.frame only):

    lookfor <- 
    function (pattern, data, ...) 
    {
        l <- lapply(data, function(x, ...) grep(pattern, x, ...))
        res <- rep(FALSE, ncol(data))
        res[grep(pattern, names(data), ...)] <- TRUE
        res <- sapply(l, length) > 0 | res
        names(res) <- names(data)
        names(res)[res]
    }
    

    First I grep each column, then I grep the column names. Then I keep only information whether grep matched anything and record it for each column separately. Instead of ... you can pass any arguments to grep. If you omit it, this function will do a simple string matching.

    Here is an example:

    > dt<- data.frame(y=1:10,x=letters[1:10],a=rnorm(10))
    > lookfor("a",dt) 
    [1] "x" "a"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using Stata to combine and analyze data for all of our agencies
I need some help with Stata. I'm not sure if this is the right
I want to write a TeX file in Stata which contains a p-value rounded
I need to export a matrix of regression results from Stata to MATLAB. I
1) Is it possible to create a vector of strings in stata? 2) If
Is there a way to make a rewrite rule to file located in a
In Stata, after a regression I know it is possible to call the elements
In my Stata do scripts, I often have to compare dates which may be
I'm trying to do a search by customerType, and I'm running into a small
I am running Logit Regression in Stata. How can I know the explanatory power

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.