I have the following file
ficheros <- c("ventas_20160522_zaragoza.csv", "pedidos_firmes_20160422_soria.csv")
And I want to create, through a function, a df in which I have the two rows mentioned and distributed in 3 columns ("Name","Date","Province")
How could I do that? I don't know if the formula would strsplit()
work well in this case.
Thanks in advance.
The problem with
split()
it is that, apparently, there is a variable number of separators, because the character appears in the name as well. It is a good example to apply regular expressions:Detail:
strcapture()
to get the 3 "groups" of datadata.frame
empty to complete the data(.+)[_](\\d+)[_](\\w+)
defines 3 capturing groups (what the parentheses enclose) and represents, the first part to date, the date and the last part without the.csv
.Dismembering the pattern
(.+)[_](\\d+)[_](\\w+)
.+
: Any character an unlimited number of times[_]
: An underscore\\d+
: A numeric character an unlimited number of times[_]
: An underscore\\w
: An alphanumeric an unlimited number of times