Search code examples
rcsvreader

R reading csv file i want to only one column with that row end with specific string value


enter image description here** above image showing sample data list, so i want to get only record that content specific keyword end like (contact); on that row. **

data <- read.csv("csv.csv", sep = ',')

# Get the max salary from data frame.
Piname <- data$col_NAME
print(Piname)
poname <- Piname[str_detect(Piname,"(end_string);")]
print(poname)

#summary(warnings())

tail(warnings(), 50)

Solution

  • We can either escape the () \\(contact\\);$ and use it as pattern

    Piname[str_detect(Piname, "\\(contact\\);$")]
    

    as by default, the ( or ) would be recognized as metacharacters to capture the characters as a group. The $ is a metacharacter to signify the end of string