I read in a file and R returns a list, like this:
list 1:
"1)" "Seo " "agad " "na " "ciad " "faclan " "a "
list 2: "cannteil " "(canntail) " "a-staigh " "dhan " "
list 3: "2)" "Seo " "sinn, " "sin " "direach " "fuirich…"
What I want is to get a vector where, if the 1st element in [[i]] has a number, then the other elements in [[i]] also get the same number and if the 1st element in [[i]] doesn't have a number, then all elements in [[i]] will have the number shown in the previous line, like this:
"1\t1)" "1\tSeo " "1\tagad " "1\tna " "1\tciad " "1\tfaclan " "1\ta " .... "2\t2)" "2\tseo", 2\tsinn....
Could anyone tell me the code for this? And, is there a way to get a vector containing only the number corresponding each word without pasting it before each word?
Thank you
My code was the following, but it didn't give me what I want (all the elements get the number 1, even those in the list starting with number 2.) What part of the code is wrong?
word=""
temp=""
for (i in 1:length(file)) {
if (grepl('\\d+\)',file[[i]][1])) {
snum=grep('\\d+',file[[i]][1])
temp=paste(snum, file[[i]], sep="\t")
} else {
temp=paste(snum,utter.short[[i]],sep="\t")
} word=c(word,temp)
}