Skip to content
Prev 256105 / 398506 Next

transform() on selective names. Is it possible?

Wonderful, or the closest to heaven I've been the whole afternoon, but
not quite there:

# begin code
N <- 300
M <- 2
x <- matrix(data=rnorm(N*M, 0, 3)-10, ncol=M, nrow=N)
y <- matrix(c(1,-2,-2,1), ncol=M, nrow=M)
z <- data.frame(x %*% y)
colnames(z) <- c('x','y')
par(mfrow=c(1,3))
plot(z, pch=5, col="blue")

whiten <- scale  # no need to re-invent the wheel, I agree
fc <- function(dfrm, coln) transform(dfrm, coln=whiten(dfrm[coln]))
colxy <- "x"
z1 <- fc(z, colxy)  # the "[" function will interpret colxy
colnames(z1)
fc <- function(dfrm, coln) transform(dfrm, coln=whiten(dfrm[,coln]))
colxy <- "x"
z2 <- fc(z, colxy)  # the "[" function will interpret colxy
colnames(z2)
#end code

What I want is to know whether I can customize the column name of the
result of the transform() call.
Your hint is fantastic, thanks there, but I keep getting into that
particular pattern of computation over and over and I wonder if it's
possible to skip a column clean-up after applying your trick.

2011/4/7 David Winsemius <dwinsemius at comcast.net>:
Cheers,
jcb!