Indranil
Indranil

Reputation: 1

Delete rows and row values if string is present

I have a data sample like this after all pivoting and transformations

CIRCLE RecordDate tenant name value
ATM_AL_WCDMA 2022-12-08 atmdza#wcdma Cells with RCA 55
ATM_AL_WCDMA 2022-12-08 atmdza#wcdma Cells with RCA (%) 55
ATM_AL_WCDMA 2022-12-08 atmdza#wcdma Cells with CIC Issues 99
ATM_AL_WCDMA 2022-12-08 atmdza#wcdma Cells with CIC Issues (%) 99
ATM_AL_WCDMA 2022-12-08 atmdza#wcdma Cells with UIC Issues 99
ATM_AL_WCDMA 2022-12-08 atmdza#wcdma Cells with UIC Issues (%) 99
ATM_AL_WCDMA 2022-12-08 atmdza#wcdma No PM data found 0
ATM_AL_WCDMA 2022-12-08 atmdza#wcdma Null counters 0

I am trying to check if string wcdma exists in column tenant and if it exists delete the rows - Cells with RCA (%) and its value in the value column. It should only delete Cells with RCA (%) in the name column and its corresponding value in the value column, tenant name should remain.

It can be achieved by separating into multiple lines, but I don't know if it achieves in a single continuous line.

Upvotes: 0

Views: 44

Answers (1)

Bensstats
Bensstats

Reputation: 1056

If I understood the question correctly, this is what you are going to need to do:

# Your Data
df <- read.csv(text = "
CIRCLE,RecordDate,tenant,name,value,
ATM_AL_WCDMA,2022-12-08,atmdza#wcdma,Cells with RCA,55,
ATM_AL_WCDMA,2022-12-08,atmdza#wcdma,Cells with RCA (%),55,
ATM_AL_WCDMA,2022-12-08,atmdza#wcdma,Cells with CIC Issues,99,
ATM_AL_WCDMA,2022-12-08,atmdza#wcdma,Cells with CIC Issues (%),99,
ATM_AL_WCDMA,2022-12-08,atmdza#wcdma,Cells with UIC Issues,99,
ATM_AL_WCDMA,2022-12-08,atmdza#wcdma,Cells with UIC Issues (%),99,
ATM_AL_WCDMA,2022-12-08,atmdza#wcdma,No PM data found,0,
ATM_AL_WCDMA,2022-12-08,atmdza#wcdma,Null counters,0",
                 header= TRUE,
                 sep=",")

# Base R Solution
df <- subset(df,select=-X)

df[grepl('wcdma',df$tenant) &grepl("Cells with RCA \\(%\\)",df$name),][c("name","value")]<-c(NA,NA)

    CIRCLE RecordDate       tenant                      name value
1 ATM_AL_WCDMA 2022-12-08 atmdza#wcdma            Cells with RCA    55
2 ATM_AL_WCDMA 2022-12-08 atmdza#wcdma                      <NA>    NA
3 ATM_AL_WCDMA 2022-12-08 atmdza#wcdma     Cells with CIC Issues    99
4 ATM_AL_WCDMA 2022-12-08 atmdza#wcdma Cells with CIC Issues (%)    99
5 ATM_AL_WCDMA 2022-12-08 atmdza#wcdma     Cells with UIC Issues    99
6 ATM_AL_WCDMA 2022-12-08 atmdza#wcdma Cells with UIC Issues (%)    99
7 ATM_AL_WCDMA 2022-12-08 atmdza#wcdma          No PM data found     0
8 ATM_AL_WCDMA 2022-12-08 atmdza#wcdma             Null counters     0

Upvotes: 1

Related Questions