Hi:
Assuming that z constitutes the last two elements of your input vector,
try2 <- function(x) {
n <- length(x)
y <- x[1:(n - 2)]
z <- x[n - 1] + x[n]
sum(y) * z
}
x0 <- 1:4# result should be 21
x1 <- 1:8# z = 15, result = 21 * 15 = 315
try2(x0)
try2(x1)
HTH,
Dennis
On
ll a room when its empty? Does the room,
the thing itself have purpose? Or do we, what's the word... imbue it."
- Jubal Early, Firefly
r-help-boun...@r-project.org wrote on 03/10/2011 08:49:25 AM:
> [image removed]
>
> [R] sum of variables in function
>
> beatleb
Dear R users,
Probably, this is quite a simpe question, but I do not find the proper way
to obtain want I need. To explain the problem, I constructed a simple
example.
Suppose I have the following function:
try1<-function(x){
y<-x[1:2]
z<-x[3:4]
y[1]*(z[1]+z[2])+y[2]*(z[1]+z[2])
}
This functio
3 matches
Mail list logo