[Solved] Remove NA inside column from Datafarme [closed]


We loop through the columns, remove the NA elements, then select the minimum number of observations after comparing all the elements in the list.

 lst <- lapply(df1, function(x) x[complete.cases(x)])
 res <- data.frame(lapply(lst, `length<-`,min(lengths(lst))))
 res
 #  cost customer.satisfaction safety time
 #1   40                    57     32   24
 #2   38                    72     30   40
 #3   36                    73     58   22

8

solved Remove NA inside column from Datafarme [closed]