[R] Skipping specified rows in scan or read.table

Paul Smith phhs80 at gmail.com
Sun Apr 13 10:50:44 CEST 2008


On Wed, Apr 9, 2008 at 7:37 PM, Ravi Varadhan <rvaradhan at jhmi.edu> wrote:
>  I have a data file, certain lines of which are character fields.  I would
>  like to skip these rows, and read the data file as a numeric data frame.  I
>  know that I can skip lines at the beginning with read.table and scan, but is
>  there a way to skip a specified sequence of lines (e.g., 1, 2, 10, 11, 19,
>  20, 28, 29, etc.) ?
>
>  If I read the entire data file, and then delete the character fields, the
>  values are still kept as factors, with each value denoted by its level.
>  Since, I have continuous variables, there are as many levels as there are
>  values.  I am unable to coerce this to "numeric" mode.  Is there a way to do
>  this so that I can then manipulate the numeric data frame?

Read the entire data file to the data frame mydata, and then delete
the character fields. Afterwards,

mydata <- edit(mydata)

and, inside edit, coerce the columns that you want to numeric.

Paul



More information about the R-help mailing list