Hi Meng,

A one-liner would be
dat*rep(z, each=nrow(dat))

Cheers,
Andrius


2012/12/30 meng <laomen...@163.com>

> hi all:
> Here's a dataframe(dat) and a vector(z):
>
> dat:
> x1     x2    x3
> 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 tedious.
> I wanna an efficient solution to do it .
>
> Any help?
>
> Many thanks!
>
> My best
>
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to