Re: [R] fill 0-row data.frame with 1 line of NAs

2012-07-11 Thread William Dunlap
potfire, TIBCO Software wdunlap tibco.com > -Original Message----- > From: Liviu Andronic [mailto:landronim...@gmail.com] > Sent: Wednesday, July 11, 2012 2:19 PM > To: William Dunlap > Cc: arun; R help > Subject: Re: [R] fill 0-row data.frame with 1 line of NAs > > On

Re: [R] fill 0-row data.frame with 1 line of NAs

2012-07-11 Thread Liviu Andronic
On Wed, Jul 11, 2012 at 9:56 PM, William Dunlap wrote: > Why does one want to replace a zero-row data.frame > with a one-row data.frame of NA's? Unless this is for > an external program that cannot handle zero-row inputs, > this suggests that there is an unnecessary limitation (i.e., > a bug) in

Re: [R] fill 0-row data.frame with 1 line of NAs

2012-07-11 Thread William Dunlap
tfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of arun > Sent: Wednesday, July 11, 2012 10:03 AM > To: Liviu Andronic > Cc: R help > Subject: Re: [R] fill 0-row data.frame

Re: [R] fill 0-row data.frame with 1 line of NAs

2012-07-11 Thread arun
es #NA   NA  NA   NA  NA    A.K. - Original Message - From: Liviu Andronic To: "r-help@r-project.org Help" Cc: Sent: Tuesday, July 10, 2012 9:15 AM Subject: [R] fill 0-row data.frame with 1 line of NAs Dear all Is there a simpler method to achie

Re: [R] fill 0-row data.frame with 1 line of NAs

2012-07-11 Thread Gabor Grothendieck
On Tue, Jul 10, 2012 at 9:15 AM, Liviu Andronic wrote: > 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.Leng

Re: [R] fill 0-row data.frame with 1 line of NAs

2012-07-11 Thread David Winsemius
On Jul 10, 2012, at 2:05 PM, Rui Barradas wrote: Hello, Em 10-07-2012 18:59, Peter Ehlers escreveu: On 2012-07-10 08:50, Brian Diggs wrote: On 7/10/2012 7:53 AM, Peter Ehlers wrote: On 2012-07-10 06:57, Rui Barradas wrote: Hello, If you write a function, it becomes less convoluted... em

Re: [R] fill 0-row data.frame with 1 line of NAs

2012-07-11 Thread Liviu Andronic
On Tue, Jul 10, 2012 at 4:53 PM, Peter Ehlers wrote: > Both this and Liviu's original solution destroy the > factor nature of 'Species' (which may not matter, of > course). How about > > > (.xb <- iris[ iris$Species=='zz', ]) > .xb <- .xb[1, ] # this probably shouldn't work, but it does. > T

Re: [R] fill 0-row data.frame with 1 line of NAs

2012-07-10 Thread Rui Barradas
Hello, Em 10-07-2012 18:59, Peter Ehlers escreveu: On 2012-07-10 08:50, Brian Diggs wrote: On 7/10/2012 7:53 AM, Peter Ehlers wrote: On 2012-07-10 06:57, Rui Barradas wrote: Hello, If you write a function, it becomes less convoluted... empty <- function(x){ if(NROW(x) == 0){

Re: [R] fill 0-row data.frame with 1 line of NAs

2012-07-10 Thread Peter Ehlers
On 2012-07-10 08:50, Brian Diggs wrote: On 7/10/2012 7:53 AM, Peter Ehlers wrote: On 2012-07-10 06:57, Rui Barradas wrote: 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)

Re: [R] fill 0-row data.frame with 1 line of NAs

2012-07-10 Thread Brian Diggs
On 7/10/2012 7:53 AM, Peter Ehlers wrote: On 2012-07-10 06:57, Rui Barradas wrote: 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$S

Re: [R] fill 0-row data.frame with 1 line of NAs

2012-07-10 Thread Peter Ehlers
On 2012-07-10 06:57, Rui Barradas wrote: 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

Re: [R] fill 0-row data.frame with 1 line of NAs

2012-07-10 Thread Rui Barradas
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 B

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

2012-07-10 Thread Liviu Andronic
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-le