Re: [R] Comparing dates in dataframes

2010-01-18 Thread James Rome
I finally figured this out with the help of Dave and Dennis. The steps I had to do were 1. Convert dates to POSIXlt 2. Create a column in each frame that was paste(date, quarter) 3. Then %in% worked instantly. gw = c(length(arr)) gw[1:length(arr[,1])]=FALSE arr[gw]=gw # put a column of 0s

Re: [R] Comparing dates in dataframes

2010-01-17 Thread James Rome
I don't think it is that simple because it is not a one-to-one match. In the arr data frame, there are many arrivals in a quarter hour with good weather on a given day. So I need to match the date and the quarter hour. And all of the rows in the weather data frame are times with good

Re: [R] Comparing dates in dataframes

2010-01-17 Thread David Winsemius
On Jan 17, 2010, at 12:37 PM, James Rome wrote: I don't think it is that simple because it is not a one-to-one match. In the arr data frame, there are many arrivals in a quarter hour with good weather on a given day. So I need to match the date and the quarter hour. And all of the rows

Re: [R] Comparing dates in dataframes

2010-01-17 Thread James Rome
On 1/17/10 1:06 PM, David Winsemius wrote: On Jan 17, 2010, at 12:37 PM, James Rome wrote: I don't think it is that simple because it is not a one-to-one match. In the arr data frame, there are many arrivals in a quarter hour with good weather on a given day. So I need to match the date

Re: [R] Comparing dates in dataframes

2010-01-17 Thread jim holtman
SInce you provided no data, it is hard to determine how to compare. If you also want the date, then the following will work: arr$GoodWeather - arr$quarter %in% gw$quarter arr$date %in% gw$date If your quarter is just the minutes of arrival, you may have to convert that to the appropriate

Re: [R] Comparing dates in dataframes

2010-01-17 Thread James Rome
Thank you Dennis. arr$gw - as.numeric(weather$Date == arr$Date arr$quarter %in% weather$quarter) seems to be what I want to do, but in fact, with the full data set, it misidentifies the rows, so I think the error message must mean something. arrr$Date -

Re: [R] Comparing dates in dataframes

2010-01-17 Thread David Winsemius
My guess (since we still have no data on which to test these ideas) is that you need either to merge() or to use a matrix created from the dates and qtr-hours entries in gw, since matching on dates and hours separately will not uniquely classify the good qtr-hours within their proper

Re: [R] Comparing dates in dataframes

2010-01-17 Thread James Rome
Here are some sample data sets. I also tried making a combined field in each set such as adq=paste(as.character(arr$Date), as.character(arr$quarter)) and similarly for the weather set, so I have unique single things to compare, but that did not seem to help much. Thanks, Jim On 1/17/10 5:50 PM,

Re: [R] Comparing dates in dataframes

2010-01-17 Thread David Winsemius
But, but, but there is no weather goodness variable in weather?!?!?! str(weather) 'data.frame': 155 obs. of 4 variables: $ Date :Class 'Date' num [1:155] 14245 14245 14245 14245 14245 ... $ minute : int 5 15 30 45 0 15 30 45 0 15 ... $ hour : int 15 15 15 15 17 17 17 17 18

Re: [R] Comparing dates in dataframes

2010-01-17 Thread James Rome
Any entry in the weather data is a good day. That is the point. And please ignore my mistake about the quarters getting too large in weather. I am being swamped with versions, and it does not matter for this purpose.. so, the bad weather days are not in the weather data set. I am trying to get

[R] Comparing dates in dataframes

2010-01-16 Thread James Rome
I have two data frames. One (arr) has all arrivals to an airport for a year, and the other (gw) has the dates and quarter hour of the day when the weather is good. arr has a Date and quarter hour column. names(arr) [1] Date weekday hour monthminute [6] quarter

Re: [R] Comparing dates in dataframes

2010-01-16 Thread Stephan Kolassa
Hi, it looks like when you read in your data.frames, you didn't tell R to expect dates, so it treats the Date columns as factors. Judicious use of something along these lines before doing your comparisons may help: arr$Date - as.Date(as.character(arr$Date),format=something) Then again, it

Re: [R] Comparing dates in dataframes

2010-01-16 Thread James Rome
I don't want to merge the data frames because there are many entries in the arrival frame for each one in the weather frame. And it is the missing dates and quarters in the weather frame that constitute the date I want, namely those arrivals that occurred in bad (or good) weather. But I will

Re: [R] Comparing dates in dataframes

2010-01-16 Thread jim holtman
If you have a vector of the quarter hours of good weather (gw), then to create the column in the arr dataframe you would do arr$GoodWeather - arr$quarter %in% gw This says that if the quarter hour of the arrival is in the 'gw' vector, set the value TRUE; otherwise FALSE. On Sat, Jan 16, 2010 at