I'm fairly new to the R language. So I have this vector containing the following:
> head(sampleVector)
[1] "| txt01 | 100 | 200 | 123.456 | 0.12345 |"
[2] "| txt02 | 300 | 400 | 789.012 | 0.06789 |"
I want to extract the lines and break each into separate pieces, with a data value per piece.
I want to get a list resultList
that eventually would print out the following:
> head(resultList)`
[[1]]`
[1] "" "txt01" "100" "200" "123.456" "0.12345"
[[2]]`
[1] "" "txt02" "300" "400" "789.012" "0.06789"
I am struggling with the strsplit()
notation and I have tried and got the following code so far:
resultList <- strsplit(sampleVector,"\\s+[|] | [|]\\s+ | [\\s+]")`
#would give me the following output`
# [[1]]`
# [1] "| txt01" "100" "200" "123.456" "0.12345 |"
Anyway I can get the output the one strsplit
call? I am guessing my notation to distinguish the delimiter + whitespace is wrong. Any help on this would be good.