[R] Read in data table, change columns from factors

David Winsemius dw|n@em|u@ @end|ng |rom comc@@t@net
Thu Jul 19 22:20:36 CEST 2018


> On Jul 19, 2018, at 12:33 PM, Rich Shepard <rshepard using appl-ecosys.com> wrote:
> 
> On Thu, 19 Jul 2018, Rich Shepard wrote:
> 
>> I have the date and elev columns converted from factors to date and
>> numeric, respectively, but still have not learned how to convert the time.
> 
>  With this dataframe structure,
> 
> str(wy2018)
> 'data.frame':	12592 obs. of  3 variables:
> $ date: Date, format: "2017-10-01" "2017-10-01" ...
> $ time: chr  "00:00" "00:30" "01:00" "01:30" ...
> $ elev: num  290 290 290 290 290 ...
> 
> what is my syntax error using chron() to convert the time column?

I have no idea. I think reaching for chron is not needed.
> 
> wy2018$time <- chron(times=wy2018$time)
> Error in convert.times(times., fmt) : format h:m:s may be incorrect
> In addition: Warning message:
> In unpaste(times, sep = fmt$sep, fnames = fmt$periods, nfields = 3) :
>  12592 entries set to NA due to wrong number of fields

That error suggests you needed either to add ":00" on hte end of your hh:mm formated data or provide a format string.

> wy2018$myTime <- chron(times= paste(wy2018$time, ":00") )


> str(wy2018)
'data.frame':	9 obs. of  5 variables:
 $ date  : Factor w/ 1 level "2017-10-01": 1 1 1 1 1 1 1 1 1
 $ time  : Factor w/ 9 levels "00:00","00:30",..: 1 2 3 4 5 6 7 8 9
 $ elev  : num  290 290 290 290 290 ...
 $ myDate: Date, format: "2017-10-01" "2017-10-01" ...
 $ myTime: 'times' num  00:00:00 00:30:00 01:00:00 01:30:00 02:00:00 ...
  ..- attr(*, "format")= chr "h:m:s"

But I think that is not the right way to go.

> 
> 
>  Adding a format as either %h:%m or just h:m makes no difference.
> 
> Rich
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law




More information about the R-help mailing list