[R] Calculating the 2th power of a vector
Chuck Cleland
ccleland at optonline.net
Tue Nov 29 17:30:12 CET 2005
?sign
> x <- rnorm(20)
> x
[1] 0.42775501 0.77370847 -2.39860006 1.75882148
[5] -0.08231117 -0.11121029 0.93786747 -1.73588115
[9] 0.92659445 -0.59913052 0.16399931 -1.08586327
[13] 0.30092859 -0.30683075 -0.87974642 1.65483615
[17] -0.05118100 0.70005335 1.86429650 1.12937824
> x^2
[1] 0.182974345 0.598624790 5.753282243 3.093453001
[5] 0.006775129 0.012367728 0.879595393 3.013283374
[9] 0.858577271 0.358957383 0.026895773 1.179099031
[13] 0.090558015 0.094145111 0.773953771 2.738482695
[17] 0.002619495 0.490074687 3.475601451 1.275495200
> x^2*sign(x)
[1] 0.182974345 0.598624790 -5.753282243
[4] 3.093453001 -0.006775129 -0.012367728
[7] 0.879595393 -3.013283374 0.858577271
[10] -0.358957383 0.026895773 -1.179099031
[13] 0.090558015 -0.094145111 -0.773953771
[16] 2.738482695 -0.002619495 0.490074687
[19] 3.475601451 1.275495200
Amir Safari wrote:
>
>
> Hi every body ,
>
> I simply want to calculate the 2th power of a vector without changing the sign of values. How it is possible in R ?
>
> Thanks a lot for any idea.
> Amir
>
>
>
> ---------------------------------
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
--
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 452-1424 (M, W, F)
fax: (917) 438-0894
More information about the R-help
mailing list