Hello! Can't figure it out - hope it's simple: # I have some value (can be anything), e.g.: x = 12 # I'd like it to become 1. # If the value is negative (again, it can be anything), e.g.: y = -12 # I'd like it to become -1. How could I do it? Thanks a lot! -- Dimitri Liakhovitski [[alternative HTML version deleted]]
You might perhaps look at: ?sign On Thu, Mar 14, 2013 at 3:41 PM, Dimitri Liakhovitski <dimitri.liakhovitski at gmail.com> wrote:> Hello! Can't figure it out - hope it's simple: > > # I have some value (can be anything), e.g.: > x = 12 > # I'd like it to become 1. > > # If the value is negative (again, it can be anything), e.g.: > y = -12 > # I'd like it to become -1. > > How could I do it? > Thanks a lot! > > -- > Dimitri Liakhovitski >-- Sarah Goslee http://www.functionaldiversity.org
Hi, On Mar 14, 2013, at 3:41 PM, Dimitri Liakhovitski wrote:> Hello! Can't figure it out - hope it's simple: > > # I have some value (can be anything), e.g.: > x = 12 > # I'd like it to become 1. > > # If the value is negative (again, it can be anything), e.g.: > y = -12 > # I'd like it to become -1. > > How could I do it?Perhaps like this?> x = (-5):5 > x[1] -5 -4 -3 -2 -1 0 1 2 3 4 5> sign(x)[1] -1 -1 -1 -1 -1 0 1 1 1 1 1 Cheers, Ben> Thanks a lot! > > -- > Dimitri Liakhovitski > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.Ben Tupper Bigelow Laboratory for Ocean Sciences 60 Bigelow Drive, P.O. Box 380 East Boothbay, Maine 04544 http://www.bigelow.org
And as a footnote to the other replies, see
help('Math',package='base')
R's online help has a number of topics that are broader than that of a
single function, and that relatively new useRs might not have seen yet.
Examples include
?Distributions (compare with ?rnorm)
and
?Startup
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
On 3/14/13 12:41 PM, "Dimitri Liakhovitski"
<dimitri.liakhovitski at gmail.com> wrote:
>Hello! Can't figure it out - hope it's simple:
>
># I have some value (can be anything), e.g.:
>x = 12
># I'd like it to become 1.
>
># If the value is negative (again, it can be anything), e.g.:
>y = -12
># I'd like it to become -1.
>
>How could I do it?
>Thanks a lot!
>
>--
>Dimitri Liakhovitski
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help at 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.