Re: [R] ifelse on data frames

From: <rolf_at_math.unb.ca>
Date: Fri 05 Jan 2007 - 18:13:57 GMT


``MrJ Man'' wrote:

> On Friday 05 January 2007 12:34, Petr Pikal wrote:
> > Hi
> >
> > you could use also another approach in case of data
> frames
> >
> > A <- as.data.frame(A)
> > A0 <- -A*log(A)
> > A0[is.na(A0)] <- 0
> I think you meant A0[which(is.na(A0))] <- 0

        He most certainly DOES NOT mean this!

	You should try things out before offering gratuitous
	advice.

	(a) A0[is.na(A0)] <- 0
		works perfectly.

	(b) A0[which(is.na(A0))] <- 0
		gets it wrong!!!

	I would have thought that

	A0[which(is.na(A0),arr.ind=TRUE)] <- 0

	would work and get it right, but it gives the
	error message

		Error in `[<-.data.frame`(`*tmp*`, which(is.na(A0),
                   	   arr.ind = TRUE), value = 0) : 
        	only logical matrix subscripts are allowed in replacement

> >
> > which changes NaN's to zeroes
> >
> > HTH
> > Petr

                                cheers,

					Rolf Turner
					rolf@math.unb.ca

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat Jan 06 11:07:40 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 06 Jan 2007 - 00:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.