1

I have a data.frame mdf that looks like this;

       date     time moon Sunrise Sunset            time.tmp
1    1.9.12  0:00:00 0.00    6:52  20:26 2013-06-12 00:00:00
2    1.9.12  1:00:00 0.00    6:52  20:26 2013-06-12 01:00:00
3    1.9.12  2:00:00 0.00    6:52  20:26 2013-06-12 02:00:00
4    1.9.12  3:00:00 0.00    6:52  20:26 2013-06-12 03:00:00
5    1.9.12  4:00:00 0.00    6:52  20:26 2013-06-12 04:00:00

when I try to use round() on the Sunrise and Sunset columns I get an error 'unused argument'. I can't see why.

This is the line of code I'm using;

round(strptime(mdf$Sunrise, format="%H:%M"), units = "hours")

and this is the error:

Error in round.POSIXt(list(sec = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  : 
  unused argument (units = "hours")

If I use this

round(strptime("6:52", format="%H:%M"), units="hours")

I get this error in return

Error in round.POSIXt(list(sec = 0, min = 52L, hour = 6L, mday = 12L,  : 
  unused argument (units = "hours")

SessionInfo() returns

R version 3.0.1 (2013-05-16)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

Any suggestions as to how to solve this error?

This line of code is part of what was suggested in another question asked here; Place 1 heatmap on another with transparency in R

Community
  • 1
  • 1
Chrisvdberge
  • 1,824
  • 6
  • 24
  • 46
  • 1
    `round(strptime("6:52", format="%H:%M"), units="hours")` works for me. Please provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Joshua Ulrich Jun 12 '13 at 14:40
  • @JoshuaUlrich you're example throws me an error. Edited the question to include this. – Chrisvdberge Jun 12 '13 at 14:48
  • Joshua's example works for me as well. Please include in your `sessionInfo` the packages you've got loaded. – Hong Ooi Jun 12 '13 at 14:50
  • 1
    Joshua's example works fine for me. Maybe you redefined `round` somewhere? Try it in a fresh session. – joran Jun 12 '13 at 14:51
  • 2
    Then something is masking `round.POSIXt` in your session. You were probably warned about this when you loaded a package, or you defined another `round.POSIXt` function yourself. – Joshua Ulrich Jun 12 '13 at 14:51
  • 1
    you can also explicitly ask for the right function by doing `base::round.POSIXt(strptime("6:52", format="%H:%M"), units="hours")` – eddi Jun 12 '13 at 15:00

1 Answers1

1

The comments suggesting that round.POSIXt was masked or redefined in the session we're very helpful. I started a fresh session and the code is working now.

Chrisvdberge
  • 1,824
  • 6
  • 24
  • 46