Replace NA in column with value in adjacent column

It didn’t work because status was a factor. When you mix factor with numeric then numeric is the least restrictive. By forcing status to be character you get the results you’re after and the column is now a character vector: TEST$UNIT[is.na(TEST$UNIT)] <- as.character(TEST$STATUS[is.na(TEST$UNIT)]) ## UNIT STATUS TERMINATED START STOP ## 1 ACTIVE ACTIVE 1999-07-06 2007-04-23 … Read more

Insert rows for missing dates/times

This is an old question, but I just wanted to post a dplyr way of handling this, as I came across this post while searching for an answer to a similar problem. I find it more intuitive and easier on the eyes than the zoo approach. library(dplyr) ts <- seq.POSIXt(as.POSIXct(“2001-09-01 0:00”,’%m/%d/%y %H:%M’), as.POSIXct(“2001-09-01 0:07”,’%m/%d/%y %H:%M’), … Read more

Remove rows with all or some NAs (missing values) in data.frame

Also check complete.cases : > final[complete.cases(final), ] gene hsap mmul mmus rnor cfam 2 ENSG00000199674 0 2 2 2 2 6 ENSG00000221312 0 1 2 3 2 na.omit is nicer for just removing all NA‘s. complete.cases allows partial selection by including only certain columns of the dataframe: > final[complete.cases(final[ , 5:6]),] gene hsap mmul mmus … Read more