Hello,
You are missing a '*' in your first try.
(As for the second, in R parenthesis are round, not [])
sqrt(var(Y1) + var(Y2))^2 - 4*(var(Y1)*(var(Y2) - cov(Y1, Y2)^2))
This written as a function becomes
fun <- function(Y1, Y2)
sqrt(var(Y1) + var(Y2))^2 - 4*(var(Y1)*(var(Y2) - cov(Y1,
Hi,
Y1<- 1:4
Y2<- 5:8
sqrt(var(Y1)+var(Y2)^2)-4*((var(Y1)*(var(Y2)-cov(Y1,Y2)^2)))
#[1] 9.515593
A.K.
- Original Message -
From: Miguel Eduardo Delgado Burbano
To: r-help@r-project.org
Cc:
Sent: Sunday, March 17, 2013 11:47 AM
Subject: [R] help with simple function
hello all
I am w
On 17-03-2013, at 16:47, Miguel Eduardo Delgado Burbano
wrote:
> hello all
>
> I am writing a quite simple script to study dental wear patterns in humans
> and I wrote this function
>
> sqrt(var(Y1)+var(Y2))^2-4(var(Y1)*(var(Y2)-cov(Y1,Y2)^2)) but appear this
> error message
>
> Error: attem
Here's an added caveat, with subsequently a more detailed explanation of the
output desired:
The data this will apply to includes a variety of whole numbers not limited
to 1 & 0, a number of which may appear consecutively and not separated by
zeros!
e.g. x<-c(3,2,0,1,0,2,0,0,1,0,0,0,0,4,1)
ans
Here's an added caveat, with subsequently a more detailed explanation of the
output desired:
The data this will apply to includes a variety of whole numbers not limited
to 1 & 0, a number of which may appear consecutively and not separated by
zeros!
e.g. x<-c(3,2,0,1,0,2,0,0,1,0,0,0,0,4,1)
answ
I'm trying to build on Jim's approach to change the parameters in the
function, with new rules:
1. if (x[i]==0) NA
2. if (x[i]>0) log(x[i]/(number of consecutive zeros immediately preceding
it +1))
x<-c(1,0,1,0,0,1,0,0,0,1,0,0,0,0,1)
# i.e. output desired = c(0, NA, -0.69, NA, NA, -1.098, N
I'm trying to build on Jim's approach to change the parameters in the
function, with new rules:
1. if (x[i]==0) NA
2. if (x[i]>0) log(x[i]/(number of consecutive zeros preceding it +1))
x<-c(1,0,1,0,0,1,0,0,0,1,0,0,0,0,1)
# i.e. output desired = c(0, NA, -0.69, NA, NA, -1.098, NA, NA, NA, -
I'm trying to build on Jim's approach to change the parameters in the
function, with new rules:
1. if (x[i]>0) log(x[i]/(number of consecutive zeros immediately preceding
it +1))
2. if (x[i]==0) NA
x<-c(1,0,1,0,0,1,0,0,0,1,0,0,0,0,1)
# i.e. output desired = c(0, NA, -0.69, NA, NA, -1.098, NA
I'm trying to build on Jim's approach to change the parameters in the
function, with new rules:
1. if (x[i]==0) NA
2. if (x[i]>0) log(x[i]/(number of consecutive zeros preceding it +1))
x<-c(1,0,1,0,0,1,0,0,0,1,0,0,0,0,1)
# i.e. output desired = c(0, NA, -0.69, NA, NA, -1.098, NA, NA, NA, -1.38,
In fact x[4,2] should = log(x[5,1]/2]
whereas x[3,2] = log(x[5,1/3])
i.e. The denominator in the log function equals the number of rows between
m==0 and m>0 (inclusive, hence the "+1")
Hope this helps!
Charles C. Berry wrote:
>
> On Tue, 27 May 2008, T.D.Rudolph wrote:
>
>>
>>
>> I have a ma
Well done Jim.
It always ends up a little more complicated than I originally hoped, but I
certainly couldn't improve on it!
jholtman wrote:
>
> Does this do what you want:
>
>> x<-c(0,1,0,0,1,0,0,0,1,0,0,0,0,1)
>> y <- rle(x)
>> result <- lapply(seq_along(y$lengths), function(.indx){
> + i
Does this do what you want:
> x<-c(0,1,0,0,1,0,0,0,1,0,0,0,0,1)
> y <- rle(x)
> result <- lapply(seq_along(y$lengths), function(.indx){
+ if (y$values[.indx] == 0)
log(y$values[.indx+1]/seq(y$lengths[.indx]+1, by=-1,
length=y$lengths[.indx]))
+ else rep(log(y$values[.indx]), y$lengths[.ind
In fact x[4,2] should = log(x[5,1]/2]
whereas x[3,2] = log(x[5,1/3])
i.e. The denominator in the log function equals the number of rows between
m==0 and m>0 (inclusive, hence the "+1")
Hope this helps!...
Charles C. Berry wrote:
>
> On Tue, 27 May 2008, T.D.Rudolph wrote:
>
>>
>>
>> I ha
On Tue, 27 May 2008, T.D.Rudolph wrote:
I have a matrix of frequency counts from 0-160.
x<-as.matrix(c(0,1,0,0,1,0,0,0,1,0,0,0,0,1))
I would like to apply a function creating a new column (x[,2])containing
values equal to:
a) log(x[m,1]) if x[m,1] > 0; and
b) for all x[m,1]= 0, log(next x[m,1
14 matches
Mail list logo