Here is a longer base R method that returns a nice looking data.frame.
setNames(do.call(rbind.data.frame,
regmatches(temp, regexec("(\\d+) \\((\\d+):(\\d+)\\)$", temp)))[-1],
paste0("V", 1:3))
Here, regexec
selects the desired numbers using the regular expression "(\d+) \((\d+):(\d+)\)$" and regmatches
returns a list of length equal to its inputs with each element a length of 4. This list is turned into a data.frame with do.call
and rbind.data.frame
and the first column, which contains the full string, is removed. Finally, setNames
replaces the ugly default names with more manageable ones.
This returns
V1 V2 V3
1 98 56 78
2 91 53 76
3 99 53 75
Note that the variables are factor variables in this context, which are usually not very useful. To convert these to numeric, you can use the dat[] <- lapply(dat, as.numeric)
paradigm.
data
temp <- c("98 (56:78)", "91 (53:76)", "99 (53:75)")