[R] fill 0-row data.frame with 1 line of NAs
Liviu Andronic
landronimirc at gmail.com
Tue Jul 10 15:15:31 CEST 2012
Dear all
Is there a simpler method to achieve the following: When I obtain an
empty data.frame after subsetting, I need for it to contain one line
of NAs. Here's a dummy example:
> (.xb <- iris[ iris$Species=='zz', ])
[1] Sepal.Length Sepal.Width Petal.Length Petal.Width Species
<0 rows> (or 0-length row.names)
> dim(.xb)
[1] 0 5
> (.xa <- data.frame(matrix(rep(NA, ncol(.xb)), 1)))
X1 X2 X3 X4 X5
1 NA NA NA NA NA
> names(.xa) <- names(.xb)
> (.xb <- .xa)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 NA NA NA NA NA
The solution I came up with is way too convoluted. Anything simpler? Regards
Liviu
--
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
More information about the R-help
mailing list