Sorry I had typo in previous email,
this typo corrected version:
Dear R experts
I have simple question, please execuse me:
#example data, the real data consists of 20000 pairs of variables
K1 <- c(1,2,1, 1, 1,1); K2 <- c(1, 1,2,2, 1,2); K3 <- c(3, 1, 3, 3, 1,
3)
M1a <- rep( K1, 100); M1b <- rep(K2, 100)
M2a <- rep(K1, 100); M2b <- rep(K1, 100)
M3a <- rep(K1, 100); M3b <- rep(K3, 100)
mydf <- data.frame(M1a, M1b, M2a, M2b, M3a, M3b)
# matrix operation
nmat <- matrix(c(paste('M', 1:3, 'a', sep = ''),
paste('M', 1:3, 'b', sep '')), 3)
coffin <- function(x) {
x <- as.vector(x)
d1cf <- ifelse(mydf[x[1]] == mydf[x[2]],0,1) # idea is if first comulm is
equal to second column then the value of d1cf is 0 else is 1
a1cf <- ifelse(mydf[x[1]] > median(mydf[x[1]]), 1, -1) # ??????????? this
my
question
# while mydf[x[1]] = mydf[x[2]] and value of
mydf[x[1]] > median(mydf[x[1]]), the value of a1cf is 1 else
# mydf[x[1]] = mydf[x[2]] and value of
mydf[x[1]] < median(mydf[x[1]]), the value of a1cf is -1
Cf <- d1cf + a1cf
return(Cf)
}
Cim <- apply(nmat, 1, coffin)
I tried hard could get a appropriate way to do the job.
Can you help me?
NIL
---------- Forwarded message ----------
From: Nilaya Sharma <nilaya.sharma@gmail.com>
Date: Wed, May 4, 2011 at 11:32 AM
Subject: simple question
To: r-help@r-project.org
Dear R experts
I have simple question, please execuse me:
#example data, the real data consists of 20000 pairs of variables
K1 <- c(1,2,1, 1, 1,1); K2 <- c(1, 1,2,2, 1,2); K3 <- c(3, 1, 3, 3, 1,
3)
M1a <- rep( K1, 100); M1b <- rep(K2, 100)
M2a <- rep(K1, 100); M2b <- rep(K1, 100)
M3a <- rep(K1, 100); M3b <- rep(K3, 100)
mydf <- data.frame(M1a, M1b, M2a, M2b, M3a, M3b)
# matrix operation
nmat <- matrix(c(paste('M', 1:3, 'a', sep = ''),
paste('M', 1:3, 'b', sep '')), 3)
coffin <- function(x) {
x <- as.vector(x)
d1cf <- ifelse(mydf[x[1]] == mydf[x[2]],0,1) # idea is if first comulm is
equal to second column then the value of d1cf is 0 else is 1
a1cf <- ifelse(mydf[x[1]] > median(df3[x[1]]), 1, -1) # ??????????? this
my
question
# while mydf[x[1]] = mydf[x[2]] and value of
mydf[x[1]] > median(df3[x[1]]), the value of a1cf is 1 else
# mydf[x[1]] = mydf[x[2]] and value of
mydf[x[1]] < median(df3[x[1]]), the value of a1cf is -1
Cf <- d1cf + a1cf
return(Cf)
}
Cim <- apply(nmat, 1, coffin)
I tried hard could get a appropriate way to do the job.
Can you help me?
NIL
[[alternative HTML version deleted]]