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 --------------------------------- [[alternative HTML version deleted]]
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
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