Thanks for your reply. I looked at the original thread, but I thought it is different to apply to my case. In my case, the number 10112, 10114, 10115, etc. each represents a unit. Then in the following lines, for example after 10112, 1 is group 1, 2 is group 2, the lines with 8 numbers after group1 and group2 represent the attributes of each group. There may be different number of groups in each unit. For example, in unit 10114, there are 3 groups: group1, group2 and group3, with their corresponding attributes following.
I want to extract all lines for each unit, no matter how many groups there are. There may be no group in one unit. How to do this then? Thanks.
sample <- "10112 1
1 0.1 0.6 0.3
7.07 2.01 0.26 0.13 4.68 0.56 0.96 1.28
2 0.2 0.2 0.6
9.49 8.51 9.67 7.92 10.19 9.14 8.96 8.64
10114 1
1 0.2 0.3 0.5
9.78 8.64 8.33 7.6 10.57 7.16 9.05 8.58
2 0.3 0.4 0.3
4.95 5.91 4.01 3.82 5.94 4.41 3.53 5.8
3 0.1 0.2 0.7
1.4 0.67 5.22 0.96 1.23 2.52 1.36 4.81
10115 1
1 0.2 0.4 0.4
10.06 10.47 8.29 9.54 11.11 9.22 9 9.89
2 0.3 0.5 0.2
6.14 3.2 0.9 4.72 5.06 4.22 1.29 2.38"
readin <- scan(text= sample, #file = "path/sample.txt",
what = character(),
sep = "\n")
split.line <- strsplit(x = readin, split = " ")