We can remove the prefix substring with trimws and read the column using read.table with sep as default space to return two column data.frame in base R
read.table(text = trimws(DATA$V1, whitespace = ".*:\\s+"),
header = FALSE, col.names = c("VAR1", "VAR2"))
VAR1 VAR2
1 9.93100 5.09200
2 6.00007 15.12480
3 1.00020 12.98753
4 3.10000 3.98532
Or may use extract from tidyr
library(tidyr)
extract(DATA, V1, into = c("VAR1", "VAR2"),
".*:\\s+([0-9.]+)\\s+([0-9.]+)", convert = TRUE)
VAR1 VAR2
1 9.93100 5.09200
2 6.00007 15.12480
3 1.00020 12.98753
4 3.10000 3.98532
If we want data.table, using the same method can read with fread after removing the prefix substring
library(data.table)
fread(text = setDT(DATA)[, trimws(V1, whitespace = ".*:\\s+")],
col.names = c("VAR1", "VAR2"))
VAR1 VAR2
<num> <num>
1: 9.93100 5.09200
2: 6.00007 15.12480
3: 1.00020 12.98753
4: 3.10000 3.98532
Or use the select option in fread
fread(text = DATA$V1, select = c(3, 4), col.names = c("VAR1", "VAR2"))
VAR1 VAR2
<num> <num>
1: 9.93100 5.09200
2: 6.00007 15.12480
3: 1.00020 12.98753
4: 3.10000 3.98532
Or read as four columns, and subset
fread(text = DATA$V1)[, .(VAR1 = V3, VAR2 = V4)]
VAR1 VAR2
<num> <num>
1: 9.93100 5.09200
2: 6.00007 15.12480
3: 1.00020 12.98753
4: 3.10000 3.98532
Or can use tstrsplit
setDT(DATA)[, c("VAR1", "VAR2") := tstrsplit(trimws(V1,
whitespace = ".*:\\s+"), " ")]
DATA <- type.convert(DATA, as.is = TRUE)
DATA
V1 VAR1 VAR2
<char> <num> <num>
1: SCORE : 9.931 5.092 9.93100 5.09200
2: SCORE : 6.00007 15.1248 6.00007 15.12480
3: SCORE : 1.0002 12.987532 1.00020 12.98753
4: SCORE : 3.1 3.98532 3.10000 3.98532