I am lost
I am lost

Reputation: 1

Replacing values in a data with conditions

I have data frame in which one factor is Soil.pH and I want to replace all values of this factor that are bigger than 3 with the value 999.

Using the code df[Soil.pH>3]<-999 I get an error of duplicate subscripts for columns.

I should probably use the replace function like replace(df,Soil.pH>3,999). Any help would be appreciated

Upvotes: 0

Views: 1955

Answers (1)

Sun Bee
Sun Bee

Reputation: 1820

You're almost there. Try this:

df$Soil.pH[df$Soil.pH > 3] <- 999

This will replace values in the data-frame.

Upvotes: 2

Related Questions