mardi 17 juillet 2018

Grepl, str_match and copy in if statement in R

I have something like that:

ID


<something>[TMOD-106]<something>

<something>[TMOD-107]<something>

REQ_SYS_100

REQ_SYS_101


And I would like to have in the next column something like that:

ID.2


[TMOD-106]

[TMOD-107]

REQ_SYS_100

REQ_SYS_101


So if there are signs "//" I want need only the ID between them, and if there are not just copy it. I have tried something like that:

if grepl "REQ" data$ID {
then
  data$col2 <- data$ID 
else 
  str_match(data$ID, ">(.*?)<") 
}

I have no idea what I am doing wrong. Any ideas? Thank you.

Aucun commentaire:

Enregistrer un commentaire