dimanche 1 janvier 2023

How to get specific strings based on complex pattern with, regular expression

path<-c("C:/Users/SEYDOU GORO/Dropbox/PC (2)/Documents/BETCLIC/DONNEES/argentina-primera-division-matches-2022-to-2022-stats.csv",
"C:/Users/SEYDOU GORO/Dropbox/PC (2)/Documents/BETCLIC/DONNEES/argentina-primera-division-matches-2022-to-2022-stats.csv",
"C:/Users/SEYDOU GORO/Dropbox/PC (2)/Documents/BETCLIC/DONNEES/france-ligue-2-matches-2021-to-2022-stats.csv",
"C:/Users/SEYDOU GORO/Dropbox/PC (2)/Documents/BETCLIC/DONNEES/germany-2-bundesliga-matches-2021-to-2022-stats.csv")

mydata<-data.frame(path=path)

I want to create new variables out of variable path

Country the pattern is: DONNEES/country name -`

League the pattern is: DONNEES/ a word - League name -matches

Year the pattern is: - The year -to

This should the resulting dataset:

                                                                                                                     path   Country           League Year
1 C:/Users/SEYDOU GORO/Dropbox/PC (2)/Documents/BETCLIC/DONNEES/argentina-primera-division-matches-2022-to-2022-stats.csv argentina primera-division 2022
2 C:/Users/SEYDOU GORO/Dropbox/PC (2)/Documents/BETCLIC/DONNEES/argentina-primera-division-matches-2022-to-2022-stats.csv argentina primera-division  202
3             C:/Users/SEYDOU GORO/Dropbox/PC (2)/Documents/BETCLIC/DONNEES/france-ligue-2-matches-2021-to-2022-stats.csv    france          ligue-2 2021
4       C:/Users/SEYDOU GORO/Dropbox/PC (2)/Documents/BETCLIC/DONNEES/germany-2-bundesliga-matches-2021-to-2022-stats.csv   germany     2-bundesliga 2021

Aucun commentaire:

Enregistrer un commentaire