Re: [R] How to multiple the vector and variables from dataframe

2012-12-31 Thread Berend Hasselman
On 31-12-2012, at 03:24, meng wrote: > > I type: > dat*rep(z,rach=nrow(dat)) > "rach" is "each" indeed,but I type "rach" mistakenly. > What's strange to me is :No error reply appears,but show me the result: >> dat*rep(z,rach=nrow(dat)) > x1x2x3 > 1 0.1 0.4 0.7 > 2 20.0 50.0

Re: [R] How to multiple the vector and variables from dataframe

2012-12-31 Thread arun
(dat)) #   x1 x2  x3 #1 0.1 40 700 #2 0.2 50 800 #3 0.3 60 900 A.K. - Original Message - From: meng To: Andrius Druzinis Cc: R help Sent: Sunday, December 30, 2012 9:24 PM Subject: Re: [R] How to multiple the vector and variables from dataframe Hi Andrius: Thanks for your reply. Your

Re: [R] How to multiple the vector and variables from dataframe

2012-12-31 Thread meng
> > >- Original Message ----- >From: meng >To: Andrius Druzinis >Cc: R help >Sent: Sunday, December 30, 2012 9:24 PM >Subject: Re: [R] How to multiple the vector and variables from dataframe > >Hi Andrius: >Thanks for your reply. >Your answer: dat*rep(z,each=n

Re: [R] How to multiple the vector and variables from dataframe

2012-12-30 Thread meng
,z,"*")) >#'data.frame':3 obs. of 3 variables: ># $ x1: num 2 5 8 ># $ x2: num 120 200 300 ># $ x3: num 2500 5000 6200 >A.K. > > > > > > > >From: meng >To: arun >Cc: R help >Sent: Sunday, De

Re: [R] How to multiple the vector and variables from dataframe

2012-12-30 Thread arun
$ x3: num  2500 5000 6200 A.K. From: meng To: arun Cc: R help Sent: Sunday, December 30, 2012 9:40 PM Subject: Re:Re: [R] How to multiple the vector and variables from dataframe Hi,arun: Yes,your answer is what I want. A little different is : data.frame(t(t(dat)*z)) Becau

Re: [R] How to multiple the vector and variables from dataframe

2012-12-30 Thread meng
s 100, which is confusing. > t(t(dat)*z) >#x1 x2 x3 >#[1,] 2 120 2500 >#[2,] 5 200 5000 >#[3,] 8 300 6200 > >A.K. > > > > > > > >- Original Message ----- >From: meng >To: R help >Cc: >Sent: Sunday, December 30, 2012 5:26 AM >

Re: [R] How to multiple the vector and variables from dataframe

2012-12-30 Thread meng
Hi Berend: Thanks for your reply. dat<-data.frame(x1=1:3,x2=4:6,x3=7:9) z<-c(0.1,10,100) #I wanna 0.1*x1,10*x2,100*x3 Option2 is similar as "dat*rep(z,each=length(z))",and the latter is simpler than Option2 in expression. At 2012-12-31 00:31:42,"Berend Hasselman" wrote: > >On 30-12-20

Re: [R] How to multiple the vector and variables from dataframe

2012-12-30 Thread meng
The following is also work: data.frame(t(t(dat)*z)) At 2012-12-31 00:40:24,"Neal H. Walfield" wrote: >At Sun, 30 Dec 2012 16:28:44 +, >Andrius Druzinis wrote: >> >> Hi Neal, >> >> Notice that c(2, 3) gets replicated into c(2, 3, 2, 3, 2, 3) and then >> multiplied by column. This is

Re: [R] How to multiple the vector and variables from dataframe

2012-12-30 Thread meng
Hi Neal, Thanks for your reply. dat<-data.frame(x1=1:3,x2=4:6,x3=7:9) z<-c(0.1,10,100) #I wanna 0.1*x1,10*x2,100*x3 According to your answer: > as.matrix(dat)*z x1x2x3 [1,] 0.1 0.4 0.7 [2,] 20.0 50.0 80.0 [3,] 300.0 600.0 900.0 The above is not what I want. What I want i

Re: [R] How to multiple the vector and variables from dataframe

2012-12-30 Thread meng
Hi Andrius: Thanks for your reply. Your answer: dat*rep(z,each=nrow(dat)) works well. But a strange thing happened: dat<-data.frame(x1=1:3,x2=4:6,x3=7:9) z<-c(0.1,10,100) #I wanna 0.1*x1,10*x2,100*x3 I type: dat*rep(z,rach=nrow(dat)) "rach" is "each" indeed,but I type "rach" mistakenly. What's s

Re: [R] How to multiple the vector and variables from dataframe

2012-12-30 Thread arun
d element in your z is 100, which is confusing.  t(t(dat)*z) #    x1  x2   x3 #[1,]  2 120 2500 #[2,]  5 200 5000 #[3,]  8 300 6200 A.K. - Original Message - From: meng To: R help Cc: Sent: Sunday, December 30, 2012 5:26 AM Subject: [R] How to multiple the vector and variables from dataf

Re: [R] How to multiple the vector and variables from dataframe

2012-12-30 Thread Andrius Druzinis
Hi Neal, Notice that c(2, 3) gets replicated into c(2, 3, 2, 3, 2, 3) and then multiplied by column. This is not the same as multiplying each column by the respective element in vector c(2, 3). Andrius 2012/12/30 Neal H. Walfield > At Sun, 30 Dec 2012 18:26:45 +0800 (CST), > meng wrote: > > >

Re: [R] How to multiple the vector and variables from dataframe

2012-12-30 Thread Andrius Druzinis
Hi Meng, A one-liner would be dat*rep(z, each=nrow(dat)) Cheers, Andrius 2012/12/30 meng > hi all: > Here's a dataframe(dat) and a vector(z): > > dat: > x1 x2x3 > 0.2 1.2 2.5 > 0.5 2 5 > 0.8 3 6.2 > > > z > [1] 10 100 100 > > I wanna do the following: > 10*x1,100*x2

Re: [R] How to multiple the vector and variables from dataframe

2012-12-30 Thread Neal H. Walfield
At Sun, 30 Dec 2012 16:28:44 +, Andrius Druzinis wrote: > > Hi Neal, > > Notice that c(2, 3) gets replicated into c(2, 3, 2, 3, 2, 3) and then > multiplied by column. This is not the same as multiplying each column by > the respective element in vector c(2, 3). I think you mean multiplied by

Re: [R] How to multiple the vector and variables from dataframe

2012-12-30 Thread Berend Hasselman
On 30-12-2012, at 11:26, meng wrote: > hi all: > Here's a dataframe(dat) and a vector(z): > > dat: > x1 x2x3 > 0.2 1.2 2.5 > 0.5 2 5 > 0.8 3 6.2 > >> z > [1] 10 100 100 > > I wanna do the following: > 10*x1,100*x2,1000*x3 > > My solution is using the loop for z and

Re: [R] How to multiple the vector and variables from dataframe

2012-12-30 Thread Neal H. Walfield
At Sun, 30 Dec 2012 18:26:45 +0800 (CST), meng wrote: > > hi all: > Here's a dataframe(dat) and a vector(z): > > dat: > x1 x2x3 > 0.2 1.2 2.5 > 0.5 2 5 > 0.8 3 6.2 > > > z > [1] 10 100 100 > > I wanna do the following: > 10*x1,100*x2,1000*x3 > > My solution is us

[R] How to multiple the vector and variables from dataframe

2012-12-30 Thread meng
hi all: Here's a dataframe(dat) and a vector(z): dat: x1 x2x3 0.2 1.2 2.5 0.5 2 5 0.8 3 6.2 > z [1] 10 100 100 I wanna do the following: 10*x1,100*x2,1000*x3 My solution is using the loop for z and dat(since the length of z is the same as ncol of dat),which is t