Re: [R] ifelse on data frames

2007-01-08 Thread Henric Nilsson
[EMAIL PROTECTED] said the following on 2007-01-05 04:18: [Using R 2.2.0 on Windows XP; OK, OK, I will update soon!] I have noticed some undesirable behaviour when applying ifelse to a data frame. Here is my code: A - scan() 1.00 0.00 0.00 0 0.0 0.027702 0.972045

Re: [R] ifelse on data frames

2007-01-05 Thread Petr Pikal
PROTECTED] To: [EMAIL PROTECTED] Copies to: r-help@stat.math.ethz.ch Subject:Re: [R] ifelse on data frames It can be explained. class(A) [1] data.frame length(A) [1] 5 class(A==0) [1] matrix length(A==0) [1] 10 class(-A*log(A)) [1

Re: [R] ifelse on data frames

2007-01-05 Thread MrJ Man
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 which changes NaN's to zeroes HTH Petr Regards

Re: [R] ifelse on data frames

2007-01-05 Thread rolf
``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!

[R] ifelse on data frames

2007-01-04 Thread maj
[Using R 2.2.0 on Windows XP; OK, OK, I will update soon!] I have noticed some undesirable behaviour when applying ifelse to a data frame. Here is my code: A - scan() 1.00 0.00 0.00 0 0.0 0.027702 0.972045 0.000253 0 0.0 A - matrix(A,nrow=2,ncol=5,byrow=T) A == 0

Re: [R] ifelse on data frames

2007-01-04 Thread talepanda
It can be explained. class(A) [1] data.frame length(A) [1] 5 class(A==0) [1] matrix length(A==0) [1] 10 class(-A*log(A)) [1] data.frame length(-A*log(A)) [1] 5 as you can see, the result of A==0 is matrix with length=10, while the result of -A*log(A) is still data.frame with length=5.