[R] empty data frame and POSIXct data types

Stefano Sofia @te|@no@@o||@ @end|ng |rom reg|one@m@rche@|t
Thu Jun 24 16:27:37 CEST 2021


Thank you Jeff and thank you Andrew

1) Yes, I understand that it is a vector, even though is.vector(c(day1, day2)) is FALSE. Andrew explained to me why: it has attributes 'class' and 'tzone'.
2) I understand now that I created a data frame with only one row, and I am trying to fit a vector of length 2. I thought that, once created an empty data frame, I could fit any vector without specifying the length since the beginning.

Now I will think about it.
Thank you
Stefano

         (oo)
--oOO--( )--OOo--------------------------------------
Stefano Sofia PhD
Civil Protection - Marche Region - Italy
Meteo Section
Snow Section
Via del Colle Ameno 5
60126 Torrette di Ancona, Ancona (AN)
Uff: +39 071 806 7743
E-mail: stefano.sofia using regione.marche.it
---Oo---------oO----------------------------------------

________________________________________
Da: Jeff Newmiller [jdnewmil using dcn.davis.ca.us]
Inviato: giovedì 24 giugno 2021 15.46
A: r-help using r-project.org; Stefano Sofia; r-help mailing list
Oggetto: Re: [R] empty data frame and POSIXct data types

1) It _is_ a vector. Why do you think it is not a vector?

2) Your data frame has one row, with an NA in the date_POSIX column. You cannot fit a vector of length 2 as a column into a data frame with only 1 row.

What are you trying to do? Do you really want to end up with a 2-row data frame or a 3 row data frame?

On June 24, 2021 6:34:31 AM PDT, Stefano Sofia <stefano.sofia using regione.marche.it> wrote:
>Dear R users,
>I know that this question is silly (I am not a R newby) but I already
>wasted quite a lot of energies trying to fill in an empty data frame
>(with "POSIXct" "POSIXt" data type).
>
>Suppose I create
>mydf <- data.frame(data_POSIX=as.POSIXct(NA), value=as.numeric(NA))
>day1 <- as.POSIXct("2018-02-01-00-00", format="%Y-%m-%d-%H-%M",
>tz="Etc/GMT-1")
>day2 <- as.POSIXct("2018-02-02-00-00", format="%Y-%m-%d-%H-%M",
>tz="Etc/GMT-1")
>
>then
>mydf$data_POSIX <- c(day1, day2)
>
>does not work, it gives me:
>"Error in `$<-.data.frame`(`*tmp*`, data_POSIX, value = c(1517439600,
>1517612400 :
>  replacement has 2 rows, data has 1"
>
>There are few basic concepts that I am missing.
>Why c(day1, day2) is not a vector?
>Why I am not able to populate my data frame?
>
>Could somebody please give me the right hints?
>Thank you for your precious help
>Stefano
>
>
>         (oo)
>--oOO--( )--OOo--------------------------------------
>Stefano Sofia PhD
>Civil Protection - Marche Region - Italy
>Meteo Section
>Snow Section
>Via del Colle Ameno 5
>60126 Torrette di Ancona, Ancona (AN)
>Uff: +39 071 806 7743
>E-mail: stefano.sofia using regione.marche.it
>---Oo---------oO----------------------------------------
>
>________________________________
>
>AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere
>informazioni confidenziali, pertanto è destinato solo a persone
>autorizzate alla ricezione. I messaggi di posta elettronica per i
>client di Regione Marche possono contenere informazioni confidenziali e
>con privilegi legali. Se non si è il destinatario specificato, non
>leggere, copiare, inoltrare o archiviare questo messaggio. Se si è
>ricevuto questo messaggio per errore, inoltrarlo al mittente ed
>eliminarlo completamente dal sistema del proprio computer. Ai sensi
>dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità
>ed urgenza, la risposta al presente messaggio di posta elettronica può
>essere visionata da persone estranee al destinatario.
>IMPORTANT NOTICE: This e-mail message is intended to be received only
>by persons entitled to receive the confidential information it may
>contain. E-mail messages to clients of Regione Marche may contain
>information that is confidential and legally privileged. Please do not
>read, copy, forward, or store this message unless you are an intended
>recipient of it. If you have received this message in error, please
>forward it to the sender and delete it completely from your computer
>system.
>
>--
>Questo messaggio  stato analizzato da Libraesva ESG ed  risultato non
>infetto.
>This message was scanned by Libraesva ESG and is believed to be clean.
>
>
>       [[alternative HTML version deleted]]
>
>______________________________________________
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://urlsand.esvalabs.com/?u=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&e=5a635173&h=06ff70f3&f=y&p=y
>PLEASE do read the posting guide
> https://urlsand.esvalabs.com/?u=http%3A%2F%2Fwww.R-project.org%2Fposting-guide.html&e=5a635173&h=e12f63e8&f=y&p=y
>and provide commented, minimal, self-contained, reproducible code.

--
Sent from my phone. Please excuse my brevity.

--

Questo messaggio  stato analizzato con Libraesva ESG ed  risultato non infetto.


________________________________

AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed urgenza, la risposta al presente messaggio di posta elettronica può essere visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system.

--
Questo messaggio  stato analizzato da Libraesva ESG ed  risultato non infetto.
This message was scanned by Libraesva ESG and is believed to be clean.



More information about the R-help mailing list