24

Possible Duplicate:
Replace contents of factor column in R dataframe

I have the data.frame

df1<-data.frame("Sp1"=1:6,"Sp2"=7:12,"Sp3"=13:18)
rownames(df1)=c("A","B","C","D","E","F")

df1
  Sp1 Sp2 Sp3
A   1   7  13
B   2   8  14
C   3   9  15
D   4  10  16
E   5  11  17
F   6  12  18

I want to replace every entry of the number 8 in the column df1$Sp2 with the number 800. I have tried:

test<-replace(df1$Sp2,df1[800,"Sp2"],5)
1

1 Answer 1

65

e.g.:

df1$Sp2[df1$Sp2 == 8] <- 800
Sign up to request clarification or add additional context in comments.

2 Comments

@Elizabeth, why not accept the answer!
When testing this, my column gets turned into an integer, anyone else experiencing anything similar?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.