The text below is an output in text format. I want to retain or extract only the numeric part of a string using R. For example, I want to extract 56.1129 (as numeric) from a file containing the text below. I am reading the text line by line and would like to extract the value associated with ‘1 Animal’. It would be great if I could convert them to columns and extract lines 2 (Variance) and 3 (pheno1) as well.
---------------------------- -------------------------------------
- - - Results from analysis of BBBt - - -
1 Animal 56.1129
2 Variance 47.6055
3 pheno1 1 103.72 0.92562
Her1 = Animal 1/pheno1 3= 0.5410 0.0162
Notice: The parameter estimates are followed by their approximate standard errors.
----------------------------------------------------------------
One option is to treat this as a fixed width file and use
read.fwf:Read the data:
The result is a data frame that you can then manipulate as you wish.