Le Jeudi 22 Février 2007 05:37, Shubha Vishwanath Karanth a écrit :
> Hi R,
>
> Here's my question about accessing the class of an object.
>
> I have an object "dat" which can take any two of the classes, ("dates"
> "times") or ("chron" "dates" "times). Note that the classes have two
> elements within it. I want to read these classes in such a way that
>
> v=class(dat) # let class(dat)= "dates" "times"
>
> If(class(dat)==v) k=1 else k=0
>
> The problem is I can't read the above class. The error which I get for
> the above if statement is as follows:
>
> Warning message:
>
> the condition has length > 1 and only the first element will be used in:
> if (class(index(intra)) == v) k = 1
>
> How should I proceed with this? Any ideas? I tried with readline to read
> the class and access it in the 'if' statement...But doesn't work :-(

Well, given your code the condition in the 'if' statement will return c(TRUE, 
TRUE), hence the warning. Executing your code piece by piece would tell you 
that.

That said, you probably rather want to use inherit() for such purposes.

HTH

-- 
  Vincent Goulet, Associate Professor
  École d'actuariat
  Université Laval, Québec 
  [EMAIL PROTECTED]   http://vgoulet.act.ulaval.ca

______________________________________________
[email protected] 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.

Reply via email to