fetch pattern from a string 0

Hi,

I have a huge data with 1794607 records in it with 7-8 different columns in it. Here's the business case which is required,

In one of the column, there are many values which represents the data. I need to make all names prefixed with xe, ge,et and irb and omit the other ones.

Column example:

aest-abc

tars-ae

xe-0/0/0.105

xe-0/0/6

xe-0/0/17

xe-0/0/18

ge-0101

How to achieve this logic ? Could someone please help me on the same.

Hi,

Just so it's clear: You want to filter all values that start with xe, ge,et and irb? So that 'xe-0/0/0.105' is kept, but the row with 'aest-abc' is removed? In that case you can filter you data like this:

library(stringr)
library(dplyr)

myData = data.frame(
  col1 = 1:3,
  col2 = c("aest-abc", "xe-0/0/0.105", "ge-0101")  
)

myData %>% filter(str_detect(col2, "^(xe|ge|et|irb)"))
#>   col1         col2
#> 1    2 xe-0/0/0.105
#> 2    3      ge-0101

You use the str_detect function from stringr package and can write RegEx to state the conditions you like.

If this is not what you want, please give a before and after example, so we know what exactly it is you like to do.

PJ

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Hey Thanks Pieter for your response.

yes, that's the approach. I did something like this. As of now, the output is correct. Let me check in graph how it comes.

Really thanks for your great help!! :slight_smile:

InterfaceThroughput$interfaceList <-  ifelse(substr(InterfaceThroughput$interfacename,1,2)== "xe","xe",
									  ifelse(substr(InterfaceThroughput$interfacename,1,2)== "ge","ge",
									  ifelse(substr(InterfaceThroughput$interfacename,1,2)== "et","et",
								      ifelse(substr(InterfaceThroughput$interfacename,1,3)== "irb","irb","others"))))

InterfaceThroughput1 <- InterfaceThroughput[InterfaceThroughput$interfaceList %in% c("xe","ge","et","irb"),]
1 Like