0

I have the following sample data:

set.seed(8760)
ID <- c(rep(1:4, each = 6))
i <- paste(rep(LETTERS[1:6], times=4))
value <- sample(1:10000, 24)

input <- data.frame(k, i, value)

wf <- data.frame("ID"=unique(k), "WF"=sample(1:365, 4))

I just can't find an efficient way to extend my input dataframe with a column that comprises of wf-values corresponding to each rows ID. Would someone help on that one?

Thanks in advance, BenR

BenR
  • 89
  • 1
  • 2
  • 9
  • `Error in data.frame(k, i, value) : object 'k' not found` – Rich Scriven Nov 03 '14 at 14:16
  • possible duplicate of [How to join data frames in R (inner, outer, left, right)?](http://stackoverflow.com/questions/1299871/how-to-join-data-frames-in-r-inner-outer-left-right) – Henrik Nov 03 '14 at 14:25

1 Answers1

0

You could use merge, assuming that k is ID

merge(input, wf, by='ID')

or use match

input$WF <- wf$WF[match(input$ID, wf$ID)]

data

input <- data.frame(ID, i, value)
set.seed(24)
wf <- data.frame(ID=unique(ID), WF=sample(1:365, 4))
akrun
  • 874,273
  • 37
  • 540
  • 662