[R] Conditioned file Import?
ripley@stats.ox.ac.uk
ripley at stats.ox.ac.uk
Mon Jan 27 20:55:03 CET 2003
On Mon, 27 Jan 2003, Robert Schick wrote:
> I'm using R 1.6.2 on Windows 2000.
>
> I have two similar sets of files in two different directories. One
> contains species presence data and environmental measurements; the other
> contains species absence data and environmental measurements for the
> same variables as the presence data.
>
> The absence datasets contain many more observations than the presence
> datasets, and I'd like to draw a random sample from these larger
> datasets upon import of the text files. I would also like to condition
> the import so that I only draw rows whose column(s) satisfy a criteria,
> e.g. where data$temp <= 0. However, I'm not seeing anyway of doing this.
>
> I know I can use something like:
>
> > test <- read.table(file="10.06.94ed.txt",header=T)
> > test2 <- test[test$temp>15,]
> > test2[sort(sample(10)),]
>
> but can I do this as I read in the file? If yes, how could I find the #
> of lines in my smaller file, and then pass that number to the sample
> call on the larger file? (Is there a wc -l equivalent in R?)
?count.fields
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list