Modérateur : Groupe des modérateurs
Code : Tout sélectionner
".+_[0-9]+_(.{3})(.{3}).+_([0-9]+)"
Code : Tout sélectionner
plateBim <- data.frame(Label = c("GRE047503_210311140001_B02f26d1.C01_0.tif:0001-0003",
"GRE047503_210311140001_B02f26d1.C01_100.tif:0001-0009"))
library(tidyr)
extract(
plateBim,
Label,
into = c("Well", "Field", "NucId"),
regex = ".+_[0-9]+_(.{3})(.{3}).+_([0-9]+)",
remove = FALSE,
convert = FALSE
)
#> Label Well Field NucId
#> 1 GRE047503_210311140001_B02f26d1.C01_0.tif:0001-0003 B02 f26 0
#> 2 GRE047503_210311140001_B02f26d1.C01_100.tif:0001-0009 B02 f26 100
Pierre-Yves Berrard a écrit :Ici, le motif serait le suivant :Code : Tout sélectionner
".+_[0-9]+_(.{3})(.{3}).+_([0-9]+)"
Code : Tout sélectionner
x = "GRE047503_210311140001_B02f26d1.C01_0.tif:0001-0003"
y = "GRE047503_210311140001_B02f26d1.C01_100.tif:0001-0009"
sub(pattern = "([[:alnum:]_.]*)_([0-9]*).tif:([[:digit:]-]*)",
replacement = "\\2",
x = c(x, y))
#> "0" "100"
Code : Tout sélectionner
(replace-regexp-in-string
"\\([[:ascii:]]*\\)_\\([0-9]*\\).tif:\\([[:ascii:]]*\\)"
"\\2"
"GRE047503_210311140001_B02f26d1.C01_100.tif:0001-0003")
Code : Tout sélectionner
plateBim_new <- extract(plateBim, ...)
Patricia OBEID a écrit :Pourriez-vous également expliciter le motif :
".+_[0-9]+_(.{3})(.{3}).+_([0-9]+)" ?
Je suis perdue ...
".+_[0-9]+_ (.{3}) (.{3}) .+_([0-9]+)"
? Well ? Field ? ?
Je ne comprends pas comment on se repère dans la chaîne de caractères pour savoir où commencer et où s'arrêter :-(
Merci de m'éclairer
Patricia
Code : Tout sélectionner
plateBim$NucId <- str_replace(plateBim$NucId,".t","")
Code : Tout sélectionner
plateBim$NucId <- str_replace(plateBim$NucId,".",""
Code : Tout sélectionner
str_replace(plateBim$NucId, "\\.t", "")
Retourner vers « Questions en cours »
Utilisateurs parcourant ce forum : Google [Bot] et 1 invité