0

I'm combining two paleoclimatology data sets into one for use in a regression model. Each data set has an integer value for time from 0-802kys.

However, one of the sets skips a year after 600kyrs (1). When I put all data into one frame, the time series with missing times is shorter, falls out of alignment with the other and restarts itself. What I am after is for the incomplete time series to have an NA value so I can omit these rows.

i.e. when v2=601 (see image 1), I want to respective columns to read NA, 601, 3.97

My code for combining is :

df_new <- cbind(Df1$Age,
                Df2$Age,
                Df1$Benthic, 
                Df2$Deut)
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • You can search on how to merge two data.frames: https://stackoverflow.com/questions/1299871/how-to-join-merge-data-frames-inner-outer-left-right – Steffen Moritz Sep 01 '20 at 05:10
  • Please add data using `dput` and not as images. Also show the expected output for the same. Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). – Ronak Shah Sep 01 '20 at 05:18

1 Answers1

0

Just merging the data.frames should be enough, since both seem to have keys to match. You just have to make sure there are additional rows created if there is no matching key.

merge(Df1,Df2, all.x = T, all.y =T)

Should probably work for you. This would be a base R solution.

all.x / all.y does the following:

logical; if TRUE, then extra rows will be added to the output, one for each row in x that has no matching row in y. These rows will have NAs in those columns that are usually filled with values from y. The default is FALSE, so that only rows with data from both x and y are included in the output.

Information on how to merge data.frames: How to join (merge) data frames (inner, outer, left, right)

Steffen Moritz
  • 7,277
  • 11
  • 36
  • 55