dim vector or data.frame
Yes. And there's also a possibility of keeping the vector as a one column data frame (using a drop=FALSE argument in indexing to avoid conversion to vectors perhaps) so that nrow() can be used. This has the disadvantage of the inefficiency of using a data frame when a vector will do, and the advantage of avoiding the test. Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." H. Gilbert Welch
On Fri, Feb 14, 2014 at 7:44 AM, Jorge I Velez <jorgeivanvelez at gmail.com> wrote:
Hi Berry, What about using NROW(input) ? Best, Jorge.- On Sat, Feb 15, 2014 at 2:26 AM, Berry Boessenkool < berryboessenkool at hotmail.com> wrote:
Hi, In my function, I want to allow input to be a vector or a data.frame. Certain operations need to be done if the length or nrows exceeds one, but since "nrow" doesn't work for vectors, I cannot simply use if( nrow(input)>1 | length(input)>1 ) ... So is there a more elegant way to do this then with the following code? if( if(is.vector(input)) length(input)>1 else nrow(input)>1 ) ... thanks ahead, Berry
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.