Re: [R] matrix logic

2006-01-11 Thread Uwe Ligges
Tom wrote: On Tue, 10 Jan 2006 20:25:23 -0500, r user [EMAIL PROTECTED] wrote: I have 2 dataframes, each with 5 columns and 20 rows. They are called data1 and data2.I wish to create a third dataframe called data3, also with 5 columns and 20 rows. I want data3 to contains the values in data1

Re: [R] matrix logic

2006-01-11 Thread Prof Brian Ripley
The equality operator is == not =. So you need is.na(data1) == FALSE (F is a variable, and FALSE is the non-truth value), or, clearer, ifelse(!is.na(data1), data1, data2) Another way is data3 - data1 data3[is.na(data1)] - data2[is.na(data1)] which is more efficient but less clear. On Tue,

Re: [R] matrix logic

2006-01-11 Thread t c
Uwe, FYI: I tried: data3 - ifelse(is.na(data1), data2, data1) It seems to me that data3 is an array of length 100. I do NOT end up with a dataset of 5 columns and 20 rows. Uwe Ligges [EMAIL PROTECTED] wrote: Tom wrote: On Tue, 10 Jan 2006 20:25:23 -0500, r user wrote: I

Re: [R] matrix logic

2006-01-11 Thread Uwe Ligges
t c wrote: Uwe, FYI: I tried: data3 - ifelse(is.na(data1), data2, data1) It seems to me that data3 is an array of length 100. I do NOT end up with a dataset of 5 columns and 20 rows. I have not read carefully enough, for a data.frame you can generalize the approach as

Re: [R] matrix logic

2006-01-11 Thread Gabor Grothendieck
The following seems close to the form you were trying. It works for matrices, not dataframes. You can use as.matrix and as.data.frame to convert back and forth: # test data data1 - data2 - matrix(1:6,3) data1[2,2] - NA data1[] - ifelse(is.na(data1), data2, data1) On 1/11/06, t c [EMAIL

Re: [R] matrix logic

2006-01-11 Thread Jacques VESLOT
I don't know how to keep factors' levels with : data.frame(mapply(function(x,y,z) ifelse(is.na(y), z, y), names(D), D, D2, SIMPLIFY=FALSE)) but in that way it's ok : data.frame(mapply(function(z,x,y) { y[is.na(y)] - x[is.na(y)] ; y }, names(D), D, D2, SIMPLIFY=F)) (?) Uwe

[R] matrix logic

2006-01-10 Thread r user
I have 2 dataframes, each with 5 columns and 20 rows. They are called data1 and data2.I wish to create a third dataframe called data3, also with 5 columns and 20 rows. I want data3 to contains the values in data1 when the value in data1 is not NA. Otherwise it should contain the values in data2.

Re: [R] matrix logic

2006-01-10 Thread Tom
On Tue, 10 Jan 2006 20:25:23 -0500, r user [EMAIL PROTECTED] wrote: I have 2 dataframes, each with 5 columns and 20 rows. They are called data1 and data2.I wish to create a third dataframe called data3, also with 5 columns and 20 rows. I want data3 to contains the values in data1 when the