Re: [R] how to not sort factors when plotting

From: Jorge Ivan Velez <jorgeivanvelez_at_gmail.com>
Date: Mon, 12 May 2008 11:00:34 -0400

Hi Lydia,

Try this:

# Function
ratio=function(x){
temp=NULL
for (n in 1:length(x)) temp=c(temp,x[n]/x[n-1]) temp
}

# Example
x=c(1,2,3,2,1,2,3)

ratio(x)
[1] 2.0000000 1.5000000 0.6666667 0.5000000 2.0000000 1.5000000

HTH, Jorge

On Mon, May 12, 2008 at 9:52 AM, Lydia N. Slobodian <lns_at_cantab.net> wrote:

> Hello. I'm trying find the ratios between each of the integers in a
> vector. I have:
>
> for (n in x) {
> ratio <- (x[n]/x[n-1])
> ratio.all <- c(ratio.all, ratio)
> }
>
> Of course this doesn't work, nor does diff(n)/diff(n-1). Is there a
> way to specify a pair of integers in a vector?
>
> Thank you,
>
> Lydia
>
> ______________________________________________
> 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.
>

        [[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. Received on Mon 12 May 2008 - 15:35:16 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 12 May 2008 - 16:30:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive