更新时间:2023-02-18 11:20:22
你想要的似乎有两部分:
There seem to be 2 parts to what you want:
对于(1),你可以:
df$team[is.na(df$team)] <- 'CRP'
同样,您可以更改数据框的其他组件
Similarly you can alter the other component of the dataframe
对于 (2) 你可以这样做:
For (2) you could do this:
if(is.na(df$playerGame[1])) {
df$playerGame[1] <- 0
}
for(i in 2:length(df$playerGame)) {
if(is.na(x[i])) {
df$playerGame[i] <- df$playerGame[i-1]
}
}
那么 df$playerGame
是:
[1] 0 1 1 2 3 3
也许有一种非常漂亮的方法可以做到这一点,但这显然是可读的......
Perhaps there is a very nifty way to do this, but this is clearly readable...