Re: [R] searching and replacing in a data frame.

2011-07-18 Thread Ashim Kapoor
Ok Josh. Many thanks for your effort. Ashim : ) On Mon, Jul 18, 2011 at 1:34 PM, Joshua Wiley wrote: > On Mon, Jul 18, 2011 at 12:22 AM, Ashim Kapoor > wrote: > > ttt <- data.frame(A = c(Inf, 0, 0), B = c(1, 2, 3)) > >> > >> apply(ttt, 2, function(x) {x[is.infinite(x)] <- 0; x}) > >> > > >

Re: [R] searching and replacing in a data frame.

2011-07-18 Thread Joshua Wiley
On Mon, Jul 18, 2011 at 12:22 AM, Ashim Kapoor wrote: >     ttt <- data.frame(A = c(Inf, 0, 0), B = c(1, 2, 3)) >> >> apply(ttt, 2, function(x) {x[is.infinite(x)] <- 0; x}) >> > > Ok thank you. That does work. What does > > apply(ttt, 1, function(x) x[is.infinite(x)] <- 0 ) > > this return. I get

Re: [R] searching and replacing in a data frame.

2011-07-18 Thread Ashim Kapoor
ttt <- data.frame(A = c(Inf, 0, 0), B = c(1, 2, 3)) > apply(ttt, 2, function(x) {x[is.infinite(x)] <- 0; x}) > > Ok thank you. That does work. What does apply(ttt, 1, function(x) x[is.infinite(x)] <- 0 ) this return. I get all 0's,but can you explai why ? Thank you. Ashim [[alterna

Re: [R] searching and replacing in a data frame.

2011-07-18 Thread Joshua Wiley
Hi, A slight modification corrects this: ttt <- data.frame(A = c(Inf, 0, 0), B = c(1, 2, 3)) apply(ttt, 2, function(x) {x[is.infinite(x)] <- 0; x}) and please do use spaces in your code. It is much more legible. Most notably spaces are after commas. Cheers, Josh On Sun, Jul 17, 2011 at 10:0

Re: [R] searching and replacing in a data frame.

2011-07-17 Thread Ashim Kapoor
Dear David, Many thanks for your reply. On Fri, Jul 15, 2011 at 5:24 PM, David Winsemius wrote: > > On Jul 15, 2011, at 5:20 AM, Ashim Kapoor wrote: > > Dear R helpers, >> >> >> Please have a look at the following : - >> >> Note : My goal is to find and replace all Inf's in a data array with 0.

Re: [R] searching and replacing in a data frame.

2011-07-15 Thread David Winsemius
On Jul 15, 2011, at 5:20 AM, Ashim Kapoor wrote: Dear R helpers, Please have a look at the following : - Note : My goal is to find and replace all Inf's in a data array with 0. t<-data.frame(A=c(Inf,0,0),B=c(1,2,3)) t A B 1 Inf 1 2 0 2 3 0 3 str(t) 'data.frame':3 obs. of

[R] searching and replacing in a data frame.

2011-07-15 Thread Ashim Kapoor
Dear R helpers, Please have a look at the following : - Note : My goal is to find and replace all Inf's in a data array with 0. > t<-data.frame(A=c(Inf,0,0),B=c(1,2,3)) > t A B 1 Inf 1 2 0 2 3 0 3 >str(t) 'data.frame':3 obs. of 2 variables: $ A: num Inf 0 0 $ B: num 1 2 3 > t[