I want to identify whether a variable is character(0), but get lost. For example, if I have > dd<-character(0) the following doesn't seem to serve as a good identifier: > dd==character(0) logical(0) So how to detect character(0)? Thanks, Gang
is.character(dd) && length(dd) == 0 should do it i think. Gabor On Thu, Nov 15, 2007 at 04:54:45PM -0500, Gang Chen wrote:> I want to identify whether a variable is character(0), but get lost. > For example, if I have > > > dd<-character(0) > > the following doesn't seem to serve as a good identifier: > > > dd==character(0) > logical(0) > > So how to detect character(0)? > > Thanks, > Gang > > ______________________________________________ > 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.-- Csardi Gabor <csardi at rmki.kfki.hu> MTA RMKI, ELTE TTK
see ?is.character and ?length something like #not tested dd <- character(0) is.character(dd) & length(dd) == 0 should do it. Gang Chen wrote:> I want to identify whether a variable is character(0), but get lost. > For example, if I have > > > dd<-character(0) > > the following doesn't seem to serve as a good identifier: > > > dd==character(0) > logical(0) > > So how to detect character(0)? > > Thanks, > Gang > > ______________________________________________ > 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.
On 11/15/2007 4:54 PM, Gang Chen wrote:> I want to identify whether a variable is character(0), but get lost. > For example, if I have > > > dd<-character(0) > > the following doesn't seem to serve as a good identifier: > > > dd==character(0) > logical(0) > > So how to detect character(0)?(length(dd) == 0) && (typeof(dd) == "character") or if you really want to be specific (and rule out things that just act like character(0) in most respects) identical(dd, character(0)) Duncan Murdoch