I've imported a csv-file to R using RStudio where I am trying to plot points per game against minutes per game. However the minutes per game is in the format mm:ss and I'm having a hard time finding how to convert it to decimal form.
Please help!
I've imported a csv-file to R using RStudio where I am trying to plot points per game against minutes per game. However the minutes per game is in the format mm:ss and I'm having a hard time finding how to convert it to decimal form.
Please help!
Given that you start with a character vector, this is relatively easy :
gives
Make sure you checked that you used
read.csv()
with the optionas.is=TRUE
. Otherwise you'll have to convert usingas.character()
.Do you need to decimalise it? If you store the data in the correct format, for example as an object of class
POSIXlt
, one of R's date-time classes, R will handle the correct handling of the times in numeric fashion. Here is an example of what I mean:First we create some dummy data for illustration purposes:
Ignore the fact that there are dates here, it is effectively ignored when we do the plot as all observations have the same date part. Next we plot this using R's formula interface:
Which produces this:
Some tuning of first solution: