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
(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
>
>
>- 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
Many thanks arun!
Your answer is the best one :)
At 2012-12-31 10:51:35,arun wrote:
>HI Meng,
>
>NO problem.
>#In fact,
>sweep(dat,2,z,"*") #will be data.frame
> # x1 x2 x3
>#1 2 120 2500
>#2 5 200 5000
>#3 8 300 6200
> str(sweep(dat,2,z,"*"))
>#'data.frame':3 obs. of 3 varia
HI Meng,
NO problem.
#In fact,
sweep(dat,2,z,"*") #will be data.frame
# x1 x2 x3
#1 2 120 2500
#2 5 200 5000
#3 8 300 6200
str(sweep(dat,2,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.
_
Hi,arun:
Yes,your answer is what I want.
A little different is :
data.frame(t(t(dat)*z))
Because I wanna get the "data frame"type, not matrix.
Thanks for your reply.
At 2012-12-31 00:59:43,arun wrote:
>HI,
>Its not clear esp
>"
>I wanna do the following:
>10*x1,100*x2,1000*x3"
>
>Did
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
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
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
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
HI,
Its not clear esp
"
I wanna do the following:
10*x1,100*x2,1000*x3"
Did you mean 10* dat[,1], 100*dat[,2], 1000*dat[,3]?
dat<-read.table(text="
x1 x2 x3
0.2 1.2 2.5
0.5 2 5
0.8 3 6.2
",sep="",header=TRUE)
z<-c(10,100,1000) # 3rd element in your z is 100, which is confusing
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:
> >
>
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
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
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
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
16 matches
Mail list logo