I have a set of text files. In each one the useful information starts from the 1st line beginning with !. In the example shown below, useful information starts from line 3.
LINES,1
TYPES,T1,I,I,N,T1
!,CODE,GROUP,MTH,COMP
*,1,16,1,"A"
However, this first line beginning with ! is located differently in different text files. For example, in another file, the useful information start from line 4.
95
LINES,1
TYPES,T1,I,I,N,T1
!,CODE,GROUP,MTH,COMP
*,1,16,1,"A"
So I need to find the line number corresponding to this line in each text file. How to do so in R? I tried to use the following code in order to extract the first letter of each row. However, this did not work out.
x <- readLines("Test_Case.txt")
First.Letter <- function(x) substring(x, 1, 1)
apply(x, 1, First.Letter)
Error in apply(x, 1, First.Letter) : dim(X) must be positive.