I have a dataset from a text file that has simply 2 columns but multiple section breaks in data, that I want to place into separate arrays, where the name of the array is the text in the 2nd column adjacent to "Ran:". Below is an sample dataset:
ABCDEFG
Authored by test
Ran: Efg$
Test: num85
1 50
2 52
3 54
Ran: pg2
Test: num85
1 40
2 60
3 80
Ran: #2
Test: num85
1 14
2 15
3 16
I've tried using the strsplit function as follows:
header = readLines("C:/My Documents/DVH Test.txt", n=17)
data = read.table("C:/My Documents/DVH Test.txt", skip=16,
col.names = c("bin", "value"))
data.split = strsplit(data, "R")
I'm not sure if I'm even using the right approach.
Any suggestions would be appreciated.
Thanks in advance.
Okay, I've tried this, but I'm getting an empty vector and the elements don't line up like yours:
data = scan("C:/My Documents/DV.txt", what="raw")
dat = readLines(textConnection(data))
dat = dat[!grepl("Ran",dat)]
dat.split = lapply(split(dat,cumsum(grepl("Test:",dat))),
function(x)
read.table(text=x,header=TRUE))