Re: [R] If() values in one dataframe then return values from another

2013-02-05 Thread arun
Hi, I am not sure about what your end result should be: >From your code, it looks like you want to replace the rows of dat1 that >contain at least a `3` with the corresponding row of dat2. Or is it only the >cell with number `3` replaced by corresponding row in dat2. dat1<- read.table(text="    

Re: [R] If() values in one dataframe then return values from another

2013-02-04 Thread Rui Barradas
Hello, Try the following. mA <- sapply(seq_len(nrow(data1)), function(i) if(any(data1[i,] == 3)) meter[i, 1] else NA) Hope this helps, Rui Barradas Em 04-02-2013 17:48, Steven Ranney escreveu: I have a large data frame ("data1") that looks like: A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A

Re: [R] If() values in one dataframe then return values from another

2013-02-04 Thread Jose Iparraguirre
Hi Steven, You are not indexing mA properly within the loop. In order not to change the elements of the object, I'll create a new vector, mA2 -not strictly necessary, though. Let's start with an empty vector: > mA2 <- rep(0,40) Now, the loop with the correct indexing: > for(i in 1:40){ + if(

Re: [R] If() values in one dataframe then return values from another

2013-02-04 Thread David Winsemius
On Feb 4, 2013, at 9:48 AM, Steven Ranney wrote: > I have a large data frame ("data1") that looks like: > >A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15 A16 A17 A18 A19 A20 > [1,] 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 > [2,] 0 0 0 0 0 1 0