0
  • a data of annual precipitation of each year in a data frame
  • a data table, where are is the information of year

I need to add the information of the annual precipitation to the data table according to the year key.

data_table <- data.frame("dat" = c(2010, 2010, 2010, 2011, 2011, 2012, 2012, 2012))

prec_data <- data.frame("variable" = c(2010, 2011, 2012),
                "value" = c(500, 435, 451))

data_table$prec <- ?? 

Thank you for your attention and answers.

Kryštof Chytrý
  • 348
  • 1
  • 3
  • 15

1 Answers1

1
 merge(data_table, prec_data, by.x="dat", by.y="variable")
Bernhard
  • 4,272
  • 1
  • 13
  • 23