Skip to content
Prev 299658 / 398503 Next

fill 0-row data.frame with 1 line of NAs

Hello,

If you write a function, it becomes less convoluted...


empty <- function(x){
	if(NROW(x) == 0){
		y <- rep(NA, NCOL(x))
		names(y) <- names(x)
		y
	}else x
}

(.xb <- iris[ iris$Species=='zz', ])
empty(.xb)


Hope this helps,

Rui Barradas

Em 10-07-2012 14:15, Liviu Andronic escreveu: