Generation

generate functionMon, 05 Jun 2023

Necesito un código que rellene los datos que tienen NA con el último dato registrado de su fila respectiva

df <- data.frame(a=c(1,2,NA,4), b=c(NA,1,2,3), c=c(1,NA,2,NA)) # Replace NA with values in the same row df[] <- lapply(df, function(x) { x[is.na(x)] <- na.locf(x, na.rm=FALSE) return(x) })

Questions about programming?Chat with your personal AI assistant