刚开始使用R。
我正在尝试更改季节数据类型以分解并重新编码为适当的季节。但是我得到一个错误class player{
vector<porto*> po;
vector<navio*> na;
int moedas;
public:
...//some functions I need
};
class navio{
char tipo;
int nSolM, nSol, aguaM, agua, cap, peixe, casas, id, xcor, ycor;
bool pesca;
public:
navio(string t, int n){
this->id=n;
}
void setCor(int x, int y);
...more funtions I need
};
必须是一个因素(或字符向量)
f
但是,当我不使用管道时,它就可以工作。
bikedf%>%
mutate(season = as.factor(season))%>%
fct_recode("Spring" = "1", "Summer" = "2",
"Fall" = "3", "Winter" = "4")
我不太了解为什么我的第一个代码无法正常工作。
答案 0 :(得分:2)
%>%
应该在mutate
内,而不是在关闭)
之后
bikedf%>%
mutate(season = as.factor(season)%>%
fct_recode("Spring" = "1", "Summer" = "2",
"Fall" = "3", "Winter" = "4"))
答案 1 :(得分:0)
我认为,如果您使用原始代码,则需要确保指定要fct_recode()
使用的变量(季节):
bikedf%>%
mutate(season = as.factor(season))%>%
fct_recode(season, "Spring" = "1", "Summer" = "2",
"Fall" = "3", "Winter" = "4")