# [R] Fwd: simple question

From: Nilaya Sharma <nilaya.sharma_at_gmail.com>
Date: Wed, 04 May 2011 11:37:19 -0400

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] == mydf[x],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] > median(mydf[x]), 1, -1) # ??????????? this my question

# while mydf[x] = mydf[x] and value of
mydf[x] > median(mydf[x]), the value of a1cf is 1 else

# mydf[x] = mydf[x] and value of mydf[x] < median(mydf[x]), 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_at_gmail.com> Date: Wed, May 4, 2011 at 11:32 AM Subject: simple question To: r-help_at_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] == mydf[x],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] > median(df3[x]), 1, -1) # ??????????? this my question

# while mydf[x] = mydf[x] and value of
mydf[x] > median(df3[x]), the value of a1cf is 1 else

# mydf[x] = mydf[x] and value of mydf[x] < median(df3[x]), 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]]

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 Thu 05 May 2011 - 06:25:12 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 Thu 05 May 2011 - 07:00:07 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.