R error: “New Column would leave holes after existing columns”

You can index RT with is.na(ACC) like this. This answer will work if RT and ACC have the same dimension.

#example data
RT <-data.frame(matrix(1:25,ncol=5))
ACC <-data.frame(matrix(rep(1,25),ncol=5))
ACC[c(1,3,5),c(2,3,4)] <-NA

#Put NA in RT where ACC is NA
RT[is.na(ACC)] <-NA
RT

  X1 X2 X3 X4 X5
1  1 NA NA NA 21
2  2  7 12 17 22
3  3 NA NA NA 23
4  4  9 14 19 24
5  5 NA NA NA 25

Leave a Comment