-----Original Message-----
From: R-help <r-help-bounces at r-project.org> On Behalf Of Luigi Marongiu
Sent: Thursday, September 2, 2021 3:35 PM
To: r-help <r-help at r-project.org>
Subject: [R] Loop over columns of dataframe and change values condtionally
Hello,
it is possible to select the columns of a dataframe in sequence with:
```
for(i in 1:ncol(df)) {
df[ , i]
}
# or
for(i in 1:ncol(df)) {
df[ i]
}
```
And change all values with, for instance:
```
for(i in 1:ncol(df)) {
df[ , i] <- df[ , i] + 10
}
```
Is it possible to apply a condition? What would be the syntax?
For instance, to change all 0s in a column to NA would `df[i][df[i == 0] =