我有2个csv文件,其中的数据看起来像运行相同的R文件,我有数百行和列运行,我希望转换1 =注册,0 =退出“” =无数据:在多列R中转换值
Test <- read.csv("..\\..\TestFile.csv", colClasses = "factor")
[1] [2] [3]
1 0
0 1
1 1
1 0 1
[1] [2] [3]
1 0
1 1
1 0
1 0 1
So, far I had tried on
revalue(Test$1, c("1" = "Enroll")) -> Test$1
revalue(Test$1, c("0" = "Quit")) -> Test$1
revalue(Test$2, c("1" = "Enroll")) -> Test$2
revalue(Test$2, c("0" = "Quit")) -> Test$2
revalue(Test$3, c("1" = "Enroll")) -> Test$3
revalue(Test$3, c("0" = "Quit")) -> Test$3
write.csv(Test, "TestFile.csv", na = "No data")
But, it promt the warning msg: The following `from` values were not present in `x`: 1.
The NA string unable to update to "No data". Please help.
我不得不尝试测试[] < - lapply(试验,函数(X)ifelse(X == 0, “注册”, “退出”)),坚果我的NA值成为退出,而不是我想要的NA值替换为无数据 – wow5
@akrun对我来说一个新事物是'%<>%',让我检查它的功能。谢谢。 –
@ SowmyaS.Manian它会改变'Test'中的值。因此,我们不需要将其分配给'Test <- Test %>%...' – akrun