sed - R read only specific row of textfile and store them in data.frame -
i have following problem. there textfile want import r. looks this:
# below, lines start minus sign , l (-l) # define loci, while start minus sign , (-i) # define epistatic interactions between loci defined. # loci must defined before interactions can defined. # experimental designs, interactions ignored. # -start model # # here data on qtls... # -t 3 number of traits # # -k 1 # trait -number 1 # # # ..chrom..markr. .recombil. .recombir. .additive. .dominance -l 1 2 19 0.0823 0.0028 1.1712 0.0000 # # qtl1 qtl2 type value # # # -k 1 # trait -number 2 # # # ..chrom..markr. .recombil. .recombir. .additive. .dominance -l 1 2 14 0.0309 0.0564 0.4635 0.0000 # # qtl1 qtl2 type value # # # -k 1 # trait -number 3 # # # ..chrom..markr. .recombil. .recombir. .additive. .dominance -l 1 15 61 0.0782 0.0261 0.1200 0.0000 # # qtl1 qtl2 type value # # # #end of block of information # -end model #
now want read rows begins -l , save them in data.frame. know way achieve this? thanks.
datl <- readlines(textconnection("# -start model # # here data on qtls... # -t 3 number of traits # # -k 1 # trait -number 1 # # # ..chrom..markr. .recombil. .recombir. .additive. .dominance -l 1 2 19 0.0823 0.0028 1.1712 0.0000 # # qtl1 qtl2 type value # # # -k 1 # trait -number 2 # # # ..chrom..markr. .recombil. .recombir. .additive. .dominance -l 1 2 14 0.0309 0.0564 0.4635 0.0000 # # qtl1 qtl2 type value # # # -k 1 # trait -number 3 # # # ..chrom..markr. .recombil. .recombir. .additive. .dominance -l 1 15 61 0.0782 0.0261 0.1200 0.0000 # # qtl1 qtl2 type value # # # #end of block of information # -end model #"))
now code:
> goodl <- grepl("^.l", datl) > datl[goodl] [1] "-l 1 2 19 0.0823 0.0028 1.1712 0.0000" [2] "-l 1 2 14 0.0309 0.0564 0.4635 0.0000" [3] "-l 1 15 61 0.0782 0.0261 0.1200 0.0000" > read.table(text=datl[goodl])[ ,-1] v2 v3 v4 v5 v6 v7 v8 1 1 2 19 0.0823 0.0028 1.1712 0 2 1 2 14 0.0309 0.0564 0.4635 0 3 1 15 61 0.0782 0.0261 0.1200 0
the 2 or 3 tricks constructing logical index pick lines have 'l' in second position , passing "good stuff" read.table
character vector , removing extraneous column of "-l"'s.
Comments
Post a Comment