0

I have a list (logs) of 3 entries, each of which are lists with 3 components each (success, details and timestamp).

To determine the class of the component timestamp of the 1st entry, I tried 2 versions of code:

Version 1

logs[[1]]["timestamp"]
$timestamp
#[1] "2015-09-14 23:01:07 UTC"

class(logs[[1]]["timestamp"])
#[1] "list"

Version 2

logs[[1]]$timestamp
#[1] "2015-09-14 23:01:07 UTC"

class(logs[[1]]$timestamp)
#[1] "POSIXct" "POSIXt"

QUESTION

Although the output of both versions give me the timestamp, why does one version (which uses []) class this component as a "list" and the other version (which uses $) classes it as "POSIXct" "POSIXt"?

View of the list

str(logs)
List of 3
 $ :List of 3
  ..$ success  : logo TRUE
  ..$ details  :List of 1
  ..$ timestamp: POSIXct[1:1], format: "2015-09-14 23:01:07"
 $ :List of 3
  ..$ success  : logo TRUE
  ..$ details  :List of 1
  ..$ timestamp: POSIXct[1:1], format: "2015-09-15 00:00:13"
 $ :List of 3
  ..$ success  : logo TRUE
  ..$ details  :List of 1
  ..$ timestamp: POSIXct[1:1], format: "2015-09-15 01:00:43"
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
Suvi
  • 1

0 Answers0