Shubha Vishwanath Karanth
2007-Feb-22 10:37 UTC
[R] Accessing the class of an object with two elements.
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 :-( Thanks in advance, Shubha [[alternative HTML version deleted]]
Vincent Goulet
2007-Feb-22 16:41 UTC
[R] Accessing the class of an object with two elements.
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 Vincent.Goulet at act.ulaval.ca http://vgoulet.act.ulaval.ca