替换R中的数据框列中的数字? [英] Replace numbers in data frame column in R?
本文介绍了替换R中的数据框列中的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
替换R数据帧中的因子列的内容
我有data.frame
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
我要替换每个条目数字8在列df1 $ Sp2与数字800.我试过:
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)
推荐答案
例如:
df1$Sp2[df1$Sp2 == 8] <- 800
这篇关于替换R中的数据框列中的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文