Why is the class() of Sys.time() length 2?












0















The class() of all elements I've encountered in R have been of length 1.



Some examples



library(dplyr)

"string" %>% class %>% length
# [1] 1

123 %>% class %>% length
# [1] 1

0.234 %>% class %>% length
# [1] 1

Sys.Date() %>% class %>% length
# [1] 1


But the class() of Sys.time() (which is itself, like the examples above, length 1) is length 2



Sys.time() %>% class %>% length
# [1] 2


Why?










share|improve this question























  • Albeit a different class, a data.table has 2 classes, the answer from here might help to explain why: stackoverflow.com/a/15986236/2449656

    – Khaynes
    Jan 20 at 7:11






  • 1





    Also, see 13.6 from here: adv-r.hadley.nz/s3.html

    – Khaynes
    Jan 20 at 7:16
















0















The class() of all elements I've encountered in R have been of length 1.



Some examples



library(dplyr)

"string" %>% class %>% length
# [1] 1

123 %>% class %>% length
# [1] 1

0.234 %>% class %>% length
# [1] 1

Sys.Date() %>% class %>% length
# [1] 1


But the class() of Sys.time() (which is itself, like the examples above, length 1) is length 2



Sys.time() %>% class %>% length
# [1] 2


Why?










share|improve this question























  • Albeit a different class, a data.table has 2 classes, the answer from here might help to explain why: stackoverflow.com/a/15986236/2449656

    – Khaynes
    Jan 20 at 7:11






  • 1





    Also, see 13.6 from here: adv-r.hadley.nz/s3.html

    – Khaynes
    Jan 20 at 7:16














0












0








0








The class() of all elements I've encountered in R have been of length 1.



Some examples



library(dplyr)

"string" %>% class %>% length
# [1] 1

123 %>% class %>% length
# [1] 1

0.234 %>% class %>% length
# [1] 1

Sys.Date() %>% class %>% length
# [1] 1


But the class() of Sys.time() (which is itself, like the examples above, length 1) is length 2



Sys.time() %>% class %>% length
# [1] 2


Why?










share|improve this question














The class() of all elements I've encountered in R have been of length 1.



Some examples



library(dplyr)

"string" %>% class %>% length
# [1] 1

123 %>% class %>% length
# [1] 1

0.234 %>% class %>% length
# [1] 1

Sys.Date() %>% class %>% length
# [1] 1


But the class() of Sys.time() (which is itself, like the examples above, length 1) is length 2



Sys.time() %>% class %>% length
# [1] 2


Why?







r






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 20 at 7:04









user5783745user5783745

9292521




9292521













  • Albeit a different class, a data.table has 2 classes, the answer from here might help to explain why: stackoverflow.com/a/15986236/2449656

    – Khaynes
    Jan 20 at 7:11






  • 1





    Also, see 13.6 from here: adv-r.hadley.nz/s3.html

    – Khaynes
    Jan 20 at 7:16



















  • Albeit a different class, a data.table has 2 classes, the answer from here might help to explain why: stackoverflow.com/a/15986236/2449656

    – Khaynes
    Jan 20 at 7:11






  • 1





    Also, see 13.6 from here: adv-r.hadley.nz/s3.html

    – Khaynes
    Jan 20 at 7:16

















Albeit a different class, a data.table has 2 classes, the answer from here might help to explain why: stackoverflow.com/a/15986236/2449656

– Khaynes
Jan 20 at 7:11





Albeit a different class, a data.table has 2 classes, the answer from here might help to explain why: stackoverflow.com/a/15986236/2449656

– Khaynes
Jan 20 at 7:11




1




1





Also, see 13.6 from here: adv-r.hadley.nz/s3.html

– Khaynes
Jan 20 at 7:16





Also, see 13.6 from here: adv-r.hadley.nz/s3.html

– Khaynes
Jan 20 at 7:16












1 Answer
1






active

oldest

votes


















2














https://stat.ethz.ch/R-manual/R-devel/library/base/html/class.html is worth a read



But in essence the ability for objects to have multiple classes allows their behavior to change in certain situations, as the order of the class vector determines the order in which methods are searched.



In the case you've observed simple objects tend to have a singular class.



Sys.time() returns a timestamp which is a bit more complex, various methods are implemented for the classes and these can differ. Therefore if one were to try the object in a context where a method exists in the second class only, it would use the second classes method.



To view the methods, try the following:



methods(class = "POSIXt")
methods(class = "POSIXct")





share|improve this answer
























  • When an object has multiple classes, is there a rule for the order in which they're returned? The quick work around for what I'm doing presently might be to simply take the first result

    – user5783745
    Jan 20 at 21:21











  • Thanks for showing methods() - very useful!

    – user5783745
    Jan 20 at 21:22











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54274317%2fwhy-is-the-class-of-sys-time-length-2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














https://stat.ethz.ch/R-manual/R-devel/library/base/html/class.html is worth a read



But in essence the ability for objects to have multiple classes allows their behavior to change in certain situations, as the order of the class vector determines the order in which methods are searched.



In the case you've observed simple objects tend to have a singular class.



Sys.time() returns a timestamp which is a bit more complex, various methods are implemented for the classes and these can differ. Therefore if one were to try the object in a context where a method exists in the second class only, it would use the second classes method.



To view the methods, try the following:



methods(class = "POSIXt")
methods(class = "POSIXct")





share|improve this answer
























  • When an object has multiple classes, is there a rule for the order in which they're returned? The quick work around for what I'm doing presently might be to simply take the first result

    – user5783745
    Jan 20 at 21:21











  • Thanks for showing methods() - very useful!

    – user5783745
    Jan 20 at 21:22
















2














https://stat.ethz.ch/R-manual/R-devel/library/base/html/class.html is worth a read



But in essence the ability for objects to have multiple classes allows their behavior to change in certain situations, as the order of the class vector determines the order in which methods are searched.



In the case you've observed simple objects tend to have a singular class.



Sys.time() returns a timestamp which is a bit more complex, various methods are implemented for the classes and these can differ. Therefore if one were to try the object in a context where a method exists in the second class only, it would use the second classes method.



To view the methods, try the following:



methods(class = "POSIXt")
methods(class = "POSIXct")





share|improve this answer
























  • When an object has multiple classes, is there a rule for the order in which they're returned? The quick work around for what I'm doing presently might be to simply take the first result

    – user5783745
    Jan 20 at 21:21











  • Thanks for showing methods() - very useful!

    – user5783745
    Jan 20 at 21:22














2












2








2







https://stat.ethz.ch/R-manual/R-devel/library/base/html/class.html is worth a read



But in essence the ability for objects to have multiple classes allows their behavior to change in certain situations, as the order of the class vector determines the order in which methods are searched.



In the case you've observed simple objects tend to have a singular class.



Sys.time() returns a timestamp which is a bit more complex, various methods are implemented for the classes and these can differ. Therefore if one were to try the object in a context where a method exists in the second class only, it would use the second classes method.



To view the methods, try the following:



methods(class = "POSIXt")
methods(class = "POSIXct")





share|improve this answer













https://stat.ethz.ch/R-manual/R-devel/library/base/html/class.html is worth a read



But in essence the ability for objects to have multiple classes allows their behavior to change in certain situations, as the order of the class vector determines the order in which methods are searched.



In the case you've observed simple objects tend to have a singular class.



Sys.time() returns a timestamp which is a bit more complex, various methods are implemented for the classes and these can differ. Therefore if one were to try the object in a context where a method exists in the second class only, it would use the second classes method.



To view the methods, try the following:



methods(class = "POSIXt")
methods(class = "POSIXct")






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 20 at 7:19









zacdavzacdav

3,5712829




3,5712829













  • When an object has multiple classes, is there a rule for the order in which they're returned? The quick work around for what I'm doing presently might be to simply take the first result

    – user5783745
    Jan 20 at 21:21











  • Thanks for showing methods() - very useful!

    – user5783745
    Jan 20 at 21:22



















  • When an object has multiple classes, is there a rule for the order in which they're returned? The quick work around for what I'm doing presently might be to simply take the first result

    – user5783745
    Jan 20 at 21:21











  • Thanks for showing methods() - very useful!

    – user5783745
    Jan 20 at 21:22

















When an object has multiple classes, is there a rule for the order in which they're returned? The quick work around for what I'm doing presently might be to simply take the first result

– user5783745
Jan 20 at 21:21





When an object has multiple classes, is there a rule for the order in which they're returned? The quick work around for what I'm doing presently might be to simply take the first result

– user5783745
Jan 20 at 21:21













Thanks for showing methods() - very useful!

– user5783745
Jan 20 at 21:22





Thanks for showing methods() - very useful!

– user5783745
Jan 20 at 21:22




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54274317%2fwhy-is-the-class-of-sys-time-length-2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Liquibase includeAll doesn't find base path

How to use setInterval in EJS file?

Petrus Granier-Deferre