I am trying to figure it out how I can use tstrisplit()
function from data.table
to split
a text by location number. I am aware of the Q1, Q2 & Q3 but these do not address my question.
as an example :
DT2 <- data.table(a = paste0(LETTERS[1:5],seq(10,15)), b = runif(6))
DT2
a b
1: A10 0.4153622
2: B11 0.1567381
3: C12 0.5361883
4: D13 0.5920144
5: E14 0.3376648
6: A15 0.5503773
I tried the following which did not work:
DT2[, c("L", "D") := tstrsplit(a, "")][]
DT2[, c("L", "D") := tstrsplit(a, "[A-Z]")][]
DT2[, c("L", "D") := tstrsplit(a, "[0-9]{1}")][]
The expectation:
a b L D
1: A10 0.4153622 A 10
2: B11 0.1567381 B 11
3: C12 0.5361883 C 12
4: D13 0.5920144 D 13
5: E14 0.3376648 E 14
6: A15 0.5503773 A 15
any help with explanation is highly appreciated.