I have a data frame like this:
d <-
read.table(header=TRUE,text='
gene 0h 4h 24h 48h 72h
1 MIB2 5.329502 5.202208 4.742011 4.8148886 2.263599
2 SLC35E2B 6.461612 6.599991 6.464688 6.5399660 6.378209
3 CALML6 5.200950 5.308204 5.848097 6.2346177 6.744116
4 CALML6 5.200950 5.308204 5.848097 6.2346177 6.744116
5 FAM213B 5.228090 5.379973 5.717725 5.7202588 6.204203
6 PRDM16 2.981332 1.538496 1.263351 0.6315327 3.622116')
and I would like to perform log2 transform on column 2:6 but keep the information of column one.
I am able to log transform column 2:6 with log(d[2:6],2)
but then I lose the gene information.
If you want to save it back into the same data.frame, then simply use:
d[, 2:6] <- log(d[2:6], 2)
d
If you want to save it to a new object, first snag a copy:
d.new <- d
d.new[, 2:6] <- log(d[2:6], 2)
d.new
You can also use cbind
if you'd like
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With