0

I have two different files which I'd like to combine to make one data frame but I've no idea how to do it! The first file has two columns; one is the date, the following is a binary code for debris flow events. Then my other file has also two columns; the date and then precipitation data.

The thing is, is that the two date columns don't all contain the same dates. The binary one is every day from April - October from 1900 - 2005, yet the precipitation file has dates from from say, 1911 to 2004, with some missing data on certain months and during certain years.

So my question is how to make a data frame which would have the date, the binary 0 or 1, and then the corresponding precip value from that particular date. I only want the precip information for the days where I have information in the binary file; the others can be disregarded.

I have tried using codes which I found in answer to other questions asked but none of them work with my issue. If I'm honest I don't really know if this is what I need. I'm hoping to end up doing a logistic regression.

I'd be really grateful if anyone could help me and suggest a way to do it! I'm also really not very technical and am not at all comfortable with R so if you could be really basic in your advice I'd appreciate it!

ymn
  • 2,175
  • 2
  • 21
  • 39

1 Answers1

0

If you want to combine data which have identical dates, take a look at %in% and intersect . Something like

# not tested. Beware.
new_dates<- intersect(data_1[,1],data_2[,1])
new_data <- cbind(new_dates,data_1[data_1[,1] %in% new_dates,2] , data_2{data_2 %in% new_dates,2])

(probably much cleaner ways with the ever-looming plyr package :-) )

Carl Witthoft
  • 20,573
  • 9
  • 43
  • 73