1

Brand new at R.

I have a table of data with two date fields: ReportingPeriodStart Classdate

I need two data sets: those rows where ReportingPeriodStart is less than Classdate and one where Reportingperiodstart is greater than Classdate.

I thought I might be able to do something like this:

PreStuff <- subset(boost, REPORTINGPERIODENDDATE < WaveStart, 
select = c(PROVIDERNAME,DEPARTMENT,SPECIALTY,
REPORTINGPERIODENDDATE,WaveStart TOSH,TOUD,TIMEINSYS,SEVENASEVENP,PJTIME,PROFSCORE)
)

but I'm getting the error: unexpected symbol in "prestuff ...."

I've looked through similar posts but each of those has a dataset that's a list of hardwired dates. I have two date fields I have to compare.

I just got R installed a few days ago and am able to use the plot(x,y) function basically.

How would one go about grabbing those rows where one datefield is less than another date field?

camille
  • 16,432
  • 18
  • 38
  • 60
  • Check out the 'lubridate' package, it makes working with dates easy. – TJ87 Feb 21 '20 at 20:34
  • [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making an R question that folks can help with. That includes a sample of data, all necessary code, and a clear explanation of what you're trying to do and what hasn't worked. – camille Feb 21 '20 at 21:23
  • Thanks for the referral to the page about making a good post. I don't understand any of it unfortunately. It will take me awhile to figure out what it all means. In the meantime, I have a table with three columns: Name Date1 Date2 I need to make two sets of data from this table: All the rows where Date1 is less than date2 and all the rows where Date1 is greater than date2. I've tried using Date1 < Date2, but I believe the error I'm getting means the less than symbol doesn't work. So I tried Lubridate and taking the difference and looking for difference <0 or difference >0. – Barbara Eckstein Feb 21 '20 at 22:30

1 Answers1

0

Your issue is the select statement. Specifically quotes and WAVESTART TOSH where most likely forgot a comma, or are dealing with implicit conversion. See the help:

The select argument exists only for the methods for data frames and matrices. It works by first replacing column names in the selection expression with the corresponding column numbers in the data frame and then using the resulting integer vector to index the columns. This allows the use of the standard indexing conventions so that for example ranges of columns can be specified easily, or single columns can be dropped (see the examples).

So

  1. You have to pass a vector of character arguments to reference the column names for select. Try c("PROVIDERNAME", ... instead of c(PROVIDERNAME, ...). Or else R will start looking for a vector logicals or characters called PROVIDERNAME in the workspace to get the indices.
  2. You have a column name with a space WaveStart TOSH. This is giving you the actual error. In matrices you can store column names with a space. But if you reference columns by character, R will either convert them to data.frame first or ask you to do it. In this case, as.data.frame.matrix would change WaveStart TOSH to WaveStart.TOSH... or you just forgot a comma.
AdamO
  • 4,283
  • 1
  • 27
  • 39