[R-sig-Geo] Change dataframe values using log and if condition
Daniel Furlan Amaral
dfamaral at usp.br
Fri Dec 29 20:51:32 CET 2017
Dear all,
I need to calculate log or log1p for all values (rows) in specific
columns of a data.frame with 5500 rows and 23 columns.
When i > 0, apply log, and when i == 0, apply log1p. So I thought I
should use a for loop with a ifelse condition, log and log1p
functions.
I have already tried many possibilities, but none solved. This is
something I tried, but the data.frame's values didn't change:
tcPainelLog <- tcPainel; cols <- names(tcPainelLog[6:17])
for (j in cols) {
for (i in 1:length(j)) {
ifelse(tcPainelLog[[i]] > 0, log(i), log1p(i))
}
}
I would appreciate any help.
Thank you.
Daniel
More information about the R-sig-Geo
mailing list