[R] deleting elements from an array/object

Gabor Grothendieck ggrothendieck at myway.com
Mon Feb 23 19:16:46 CET 2004



You can create a new data frame and subset it:

myHist.df <- data.frame(counts = myHist$counts, mids = myHist$mids )
myHist.df <- subset( myHist, counts > 0 )
lm( mids ~ log(counts), data = myHist.df )

---
Date:   Mon, 23 Feb 2004 18:40:22 +0100 (CET) 
From:   =?iso-8859-1?q?Fulvio=20Copex?= <copellifulvio at yahoo.it>
To:   <r-help at stat.math.ethz.ch> 
Subject:   [R] deleting elements from an array/object 

 
Hello,
I created a simple histogram with:
myHist<-hist(myData)
the object myHist now has two arrays (among the others):

myHist$mids
myHist$counts

Since myHist$counts contains some "0", and I want to calculate the linear fit among myHist$mids and log(myHist$counts), I want remove the elements of both arrays where these "0" occurs.

which are the possible solutions to this problem?
(I'd like to avoid getting the indexes...)

Thanks a lot,
copex




More information about the R-help mailing list