Filling NA row values with nearest right side row value in R
问题 I want to convert the given dataframe from c1 c2 c3 c4 c5 VEG PUFF <NA> 12 <NA> <NA> 78.43 CHICKEN PUFF <NA> 16 <NA> 88.24 <NA> BAKERY Total <NA> <NA> 28 <NA> 84.04 to c1 c2 VEG PUFF 12 78.43 CHICKEN PUFF 16 88.24 BAKERY Total 28 84.04 I tried two methods but i didnt get accurate results it is sometimes taking left side row value step1 <- t(na.locf(t(df), fromLast=T)) step2 <- t(na.locf(t(step1), fromLast=F)) library(dplyr) MyReplace = function(data) {data %>% t %>% na.locf(.,,T) %>% na.locf