I may be biased, but I would suggest my cSplit function for this problem.
Firstly, I assume that we start with the following (single column) data.frame (where there are several spaces between the value of "date" and the value of "rate").
df <- data.frame( Date = c("1971-04-01 7.31", "1971-05-01 7.43", "1971-06-01 7.53", "1971-07-01 7.60", "1971-08-01 7.70", "1971-09-01 7.69", "1971-10-01 7.63", "1971-11-01 7.55", "1971-12-01 7.48", "1972-01-01 7.44"))
Next, get the cSplit function from my GitHub Gist and use it. You can divide by regex (here are a few spaces).
cSplit(df, "Date", "\\s+", fixed = FALSE) # Date_1 Date_2 # 1: 1971-04-01 7.31 # 2: 1971-05-01 7.43 # 3: 1971-06-01 7.53 # 4: 1971-07-01 7.60 # 5: 1971-08-01 7.70 # 6: 1971-09-01 7.69 # 7: 1971-10-01 7.63 # 8: 1971-11-01 7.55 # 9: 1971-12-01 7.48 # 10: 1972-01-01 7.44
Since the function converts a data.frame to data.table , you have access to setnames , which will allow you to rename your columns in place.
setnames(cSplit(df, "Date", "\\s+", fixed = FALSE), c("Dates", "Rates"))[] # Dates Rates # 1: 1971-04-01 7.31 # 2: 1971-05-01 7.43 # 3: 1971-06-01 7.53 # 4: 1971-07-01 7.60 # 5: 1971-08-01 7.70 # 6: 1971-09-01 7.69 # 7: 1971-10-01 7.63 # 8: 1971-11-01 7.55 # 9: 1971-12-01 7.48 # 10: 1972-01-01 7.44
A5C1D2H2I1M1N2O1R2T1
source share