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 8486561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:58:44+00:00 2026-06-10T20:58:44+00:00

I have a pattern list patternlist <- list(‘one’ = paste(c(‘a’,’b’,’c’),collapse=|), ‘two’ = paste(1:5,collapse=|), ‘three’

  • 0

I have a pattern list

patternlist <- list('one' = paste(c('a','b','c'),collapse="|"), 'two' = paste(1:5,collapse="|"), 'three' = paste(c('k','l','m'),collapse="|"))

that I want to select from to extract rows from a data frame

dataframez <- data.frame('letters' = c('a','b','c'), 'numbers' = 1:3, 'otherletters' = c('k','l','m'))

with this function

pattern.record <- function(x, column="letters", value="one")
{
  if (column %in% names(x))
  {
   result <- x[grep(patternlist$value, x$column, ignore.case=T),]
  }
  else
  {
    result <- NA
  }
  return(result)
}

oddly enough, I get an error when I run it:

> pattern.record(dataframez)
 Error in grep(patternlist$value, x$column, ignore.case = T) : 
  invalid 'pattern' argument
  • 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-10T20:58:46+00:00Added an answer on June 10, 2026 at 8:58 pm

    The problem is your use of the `$` operator.

    In your function, it is looking a column \ named element called column

    It is far simpler here to use `[[`

    Then x[[column]] uses what column is defined as, not column as a name.

    The relevant lines in ?`$` are

    Both [[ and $ select a single element of the list. The main difference is that $ does not allow computed indices, whereas [[ does. x$name is equivalent to x[[“name”, exact = FALSE]]. Also, the partial matching behavior of [[ can be controlled using the exact argument.

    You are trying to use value and column as computed indices (i.e. computing what value and column are defined as), thus you need `[[`.

    The function becomes

    pattern.record <- function(x, column="letters", value="one", pattern_list)
    {
      if (column %in% names(x))
      {
        result <- x[grep(pattern_list[[value]], x[[column]], ignore.case=T),]
      }
      else
      {
        result <- NA
      }
      return(result)
    }
    
    pattern.record(dataframez, patternlist = pattern_list)
    
    ##   letters numbers otherletters
    ## 1       a       1            k
    ## 2       b       2            l
    ## 3       c       3            m
    

    note that I’ve also added an argumentpattern_list so it does not depend on an object named patternlist existing somewhere in the parent environments (in your case the global environment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that uses Pattern#compile and a Matcher to search a list
I have this pattern where I need to select any random element from a
i have a code to get a list of pattern from a website: https://noembed.com/providers
I have encountered this pattern (\w+) and from http://gskinner.com/RegExr/ site I understand that \w
I have a pattern with a small list of words that are illegal to
I have a list like this: ['Ww','Aa','Bb','Cc','ww','AA','BB','CC'] And continuing in such a pattern, with
I've looked around and cannot figure this one out: I have a object that
I would like to be able to have a pattern that matches only expressions
In the following code I have to reuse the Active Pattern result three times
I have a list of strings. Each string follows the pattern {Path}\UpdateTo{Version}-{Order}. I need

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.