[R] read data into R with some constraints

Pierre Kleiber pkleiber at honlab.nmfs.hawaii.edu
Thu Jan 11 20:18:14 CET 2001


You can filter the data after reading as follows:

> rawdata <- read.csv("data.csv", sep=",",header=FALSE)
> rawdata <- rawdata[apply(rawdata,1,function(x)all(x>=0)),]

   Cheers, Pierre

Yu-Ling Wu wrote:
> 
> Hi,
> 
> I have a big data file (over 30,000 records) looks
> like this:
> 
> 100, 20, 46, 70
> 103,  0, 22, 45
> 117, -1, 34, 65
> 120, 15,  0, 25
> 113,  0,  -1, 32
> 142, -1, -1, 55
> .....
> 
> I want to read only those records having positive
> values in all of the  four
> columns. That is, I don't want to read record # 3, 5,
> and 6 into R. However,
> when I type:
> 
> read.csv("data.csv", sep=",")  -> rawdata
> 
> it reads the whole thing into R including those
> records I don't want.
> Could anyone tell me how I can read only those records
> I want?
> 
> Thanks,
> Yu-Ling Wu
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Photos - Share your holiday photos online!
> http://photos.yahoo.com/
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

-- 
-----------------------------------------------------------------
Pierre Kleiber             Email: pkleiber at honlab.nmfs.hawaii.edu
Fishery Biologist                     Tel: 808 983-5399/737-7544
NOAA FISHERIES - Honolulu Laboratory         Fax: 808 983-2902
2570 Dole St., Honolulu, HI 96822-2396 
-----------------------------------------------------------------
 "God could have told Moses about galaxies and mitochondria and
  all.  But behold... It was good enough for government work."
-----------------------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list