[R] deleting elements from an array/object

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Feb 23 19:51:38 CET 2004


It would be better to have a data frame for this purpose, so

myHist2 <- as.data.frame(myhist[c("counts", mids")])
myHist2 <- myHist2[myHist2$counts > 0, ]
lm(log(counts) ~ mids, data=myHist2)

should set this up for you, or even you could use

myHist2 <- as.data.frame(myhist[c("counts", mids")])
lm(log(counts) ~ mids, data=myHist2, subset=counts > 0)


On Mon, 23 Feb 2004, Fulvio Copex wrote:

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

vectors not arrays, I believe.

> 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...)

-- 
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