I am using R 2.1.1 in an windows XP environment. I have 2 dataframes, temp1 and temp2. Each dataframe has 20 variables (“cocolumns") and 525 observations (“rows”). All variables are numeric. I want to create a new dataframe that also has 20 columns and 525 rows. The values in this dataframe should be the sum of the 2 other dataframe. (i.e. temp1$column 1+temp2$column1, temp1$column2+temp2$column2, etc) What is the best/easiest way to accomplish this? Is I wish to "multiply" (instead of sum) the columns, how do I? I tried: temp3<-as.matrix(temp1)+as.matrix(temp2) I get the following error message: “Error in as.matrix(temp1) + as.matrix(temp2) : non-numeric argument to binary operator” --------------------------------- [[alternative HTML version deleted]]
> I am using R 2.1.1 in an windows XP environment. > > I have 2 dataframes, temp1 and temp2. > > Each dataframe has 20 variables (?cocolumns") and > 525 observations (?rows?). All variables are > numeric. > > I want to create a new dataframe that also has 20 > columns and 525 rows. The values in this dataframe > should be the sum of the 2 other dataframe. > > (i.e. temp1$column 1+temp2$column1, > temp1$column2+temp2$column2, etc) > > What is the best/easiest way to accomplish this? > > Is I wish to "multiply" (instead of sum) the > columns, how do I? > > I tried: > > temp3<-as.matrix(temp1)+as.matrix(temp2) > > I get the following error message: ?Error in > as.matrix(temp1) + as.matrix(temp2) : > non-numeric argument to binary operator? > > > > ---------------------------------> $16.99/mo. or less
> I have 2 dataframes, temp1 and temp2. > > Each dataframe has 20 variables (“cocolumns") and 525 observations >(“rows”). All variables are numeric. > > I want to create a new dataframe that also has 20 columns and 525 rows. >The values in this dataframe should be >the sum of the 2 other dataframe.>foo <- data.frame(c(1,1,1,1),c(2,2,2,2)) >bar <- data.frame(c(1,2,3,4),c(5,6,7,8)) >foo+barc.1..1..1..1. c.2..2..2..2. 1 2 7 2 3 8 3 4 9 4 5 10 If your data frames are actually data frames, it should work.>class(foo)[1] "data.frame"
On 4 Jan 2006 at 14:10, r user wrote: Date sent: Wed, 4 Jan 2006 14:10:24 -0800 (PST) From: r user <ruser2006 at yahoo.com> To: rhelp <r-help at stat.math.ethz.ch> Subject: [R] matrix math> I am using R 2.1.1 in an windows XP environment. > > I have 2 dataframes, temp1 and temp2. > > Each dataframe has 20 variables (?cocolumns") and 525 observations > (?rows?). All variables are numeric. > > I want to create a new dataframe that also has 20 columns and 525 > rows. The values in this dataframe should be the sum of the 2 other > dataframe. > > (i.e. temp1$column 1+temp2$column1, temp1$column2+temp2$column2, > etc) > > What is the best/easiest way to accomplish this? > > Is I wish to "multiply" (instead of sum) the columns, how do I? > > I tried: > > temp3<-as.matrix(temp1)+as.matrix(temp2) > > I get the following error message: ?Error in as.matrix(temp1) + > as.matrix(temp2) : > non-numeric argument to binary operator?Hi although you think all variables are numeric they probably are not. what does str(temp1) or str(temp2) tells you HTH Petr> > > > --------------------------------- > > [[alternative HTML version deleted]] > >Petr Pikal petr.pikal at precheza.cz