Dear R users,
I am trying to read a text file into R. the text file looks as shown below
(data1). I want to skip the text lines and collect all lines starting
with specific marker(s).
Example in below, I want to collect all lines which start with -1000 and
-1001
If the model results in successful convergence, each run will result in 6
lines per table. I was trying to read the 3rd and 4th line from every block
of 6 lines using the following.
#################
n=2 # example only first 2 runs
patt2=NULL
for(ser1 in unique(1:n))
{ patt1 = c(6*ser1-3, 6*ser1-2)
patt2=c(patt2,patt1)
}
see1= read.delim("data1.txt", header=F)
see2 =as.character(see1[,1])
see3 = see2[patt2]
writeLines(see3, "see3")
see4 = read.table("see3", header=T, sep='')
see4
V1 V2 V3 V4
1 -1000 2.0 2.0 2.0
2 -1001 0.5 0.5 0.5
3 -1000 2.0 2.0 5.2
4 -1001 0.4 0.4 0.5
######################
But then when convergence fails there are only 4 lines generated (see
table 3) for that run. In the model with 1000 or more runs, we don’t know
which run will fail to converge. Hence using the pattern of 6 line blocks
doesn’t work. Is there a way to directly just read all the lines starting
with -1000 and -1001 ?
Thank you for your time
##data1
table:1 conditional estimation
iteration par1 par2 par3
-1000 2 2 2
-1001 0.5 0.5 0.5
-1002 0 0 0
-1003 0 0 0
table:2 conditional estimation
iteration par1 par2 par3
-1000 2 2 5.2
-1001 0.4 0.4 0.5
-1002 0 0 0
-1003 0 0 0
table:3 conditional estimation
iteration par1 par2 par3
-1000 3.1 2.2 4.2
-1001 0.5 0.5 0.5
table:4 conditional estimation
iteration par1 par2 par3
-1000 2 1.2 2
-1001 0.5 0.4 0.5
-1002 0 0 0
-1003 0 0 0
##################
--
Navin Goyal
[[alternative HTML version deleted]]