Hi all. I am not a programmer, but through a stepwise approach have learned basic functions of RStudio from readings in the community and Google. My goal is to make a PDF report containing many plots for my large data sets. I currently do this in excel which is painfully slow and ultimately I want to analyze and update my data in realtime (every day) over the 3-4 week study period - this allows us to recognize trends during studies.
Using a small test file (.txt format) and ggplot, I have been able to produce several plots in a PDF file; all my plots use time (days) since start of study as the x-axis.
My next step, and the one which I am stuck on, it working with dates in the dataset to compute time since start of study; this new variable would be my X-axis data for all plots. I have attached a test file that I am working with. Format of dataset is date, hours, mins, secs, V1, V2. I am able to change the date to any format (YYYY-MM-DD, dd/MM/YY) before importing into RStudio - I have tried many different options both in format and RStudio import options (ie. read table, csv)
What I want to do is create a new variable (NewVar) from dataset location [1,1] (ie. the first date the study began) and transform the date to a number. Was trying this:
NewVar <- dataset [1,1]
transformed.dataset <- transform(dataset, NewDate = V1 - NewVar)
- V1= date column
The errors I receive, depending upon how I import / arrange date are either :
- In Ops.factor(V1, NewVar) : ‘-’ not meaningful for factors
- non-numeric argument to binary operator
I saw online examples on how to calculate timediff, but none that involve transform function. I'm guessing I'm not presenting the date to Rstudio in a format that it can perform a mathematical function.
My ultimate goal is to add days (from date calculation) + time of day (hh,mm,ss as a fraction of a day) to produce an X-value for each variable ; I have worked out the time of day function
Any help would be appreciated. I can provide more code if needed
Thanks in advance, GooberBoy