[R] Forward of moderated message
David Winsemius
dwinsemius at comcast.net
Fri Apr 20 16:48:04 CEST 2012
On Apr 20, 2012, at 6:57 AM, Adrian Duşa wrote:
> One solution among many:
>
> seq(970, 970 - 30*14, by=-30)
>
>
> If you want to be fancy, a function can be easily written:
> seqf <- function(startp, lengthv, byv) {
> seq(startp, startp + (lengthv - 1)*byv, by=byv)
> }
>
> seqf(970, 15, -30)
> [1] 970 940 910 880 850 820 790 760 730 700 670 640 610 580 550
>
A slightly more verbose but potentially more generalizable solution:
> Reduce("-", rep(30, 15), init=1000, accumulate=TRUE)
[1] 1000 970 940 910 880 850 820 790 760 730 700 670
640 610 580 550
An application to construct a geometrically declining sequence of
specific length:
> Reduce("*", rep(.75, 15), init=1000, accumulate=TRUE)
[1] 1000.00000 750.00000 562.50000 421.87500 316.40625
237.30469 177.97852 133.48389
[9] 100.11292 75.08469 56.31351 42.23514 31.67635
23.75726 17.81795 13.36346
--
David.
>
>
> Hth,
> Adrian
>
> On Fri, Apr 20, 2012 at 13:45, <r-help-bounces at r-project.org> wrote:
>>
>>
>> ---------- Forwarded message ----------
>> From: uday <uday_143_4u at hotmail.com>
>> To: r-help at r-project.org
>> Cc:
>> Date: Fri, 20 Apr 2012 02:14:03 -0700 (PDT)
>> Subject: vector subtraction
>> I would like to calculate vector from existing value
>> e.g
>> v <- 1000
>> s <- 30
>> d1 <- v-s
>> d1 <- 970
>> d2 <- d1 -s
>> d2 <- 940
>> d 3 <- d2-s
>> d3 <- 910
>> :
>> :
>> d15 <- .....
>>
>> so how I should get vector of length 15 d < - 970,940 ,
>> 910 ,
>> .......
>>
>> --
>> View this message in context: http://r.789695.n4.nabble.com/vector-subtraction-tp4573299p4573299.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>>
>
>
>
> --
> Adrian Dusa
> Romanian Social Data Archive
> 1, Schitu Magureanu Bd.
> 050025 Bucharest sector 5
> Romania
> Tel.:+40 21 3126618 \
> +40 21 3120210 / int.101
> Fax: +40 21 3158391
>
> ______________________________________________
> 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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list