Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
特别是我对等价物感兴趣
df.fillna(method='ffill')
和
df.fillna(method='bfill')
我们可以na.locf使用zoo
na.locf
zoo
library(zoo) na.locf(df)
对于第二种情况,
na.locf(df, fromLast=TRUE)
set.seed(24) df <- as.data.frame(matrix(sample(c(1:3, NA), 5*4, replace=TRUE), 5, 4))