카테고리 없음
[아르 자형] R-NA 값 제거
행복을전해요
2021. 1. 29. 00:56
첫 번째 NA 앞에 값이 없으면 일부 기본값을 설정해야합니다. 다음 예에서는 0으로 설정했습니다.
# create new data.frame with score0 = 0 as first column
newdata <- data.frame(newdata$tm1, score0=rep(0,nrow(newdata)), newdata[,-1])
# apply function na.locf to every row
a <- t(apply(newdata[,-c(1)], 1, na.locf))
# append to original data.frame (this will keep the column score0)
newdata[,2:ncol(newdata)] <- a
출처
https://stackoverflow.com/questions/22039798