I have two tables with information that I would like to join with a testcase as key. I could first join them, then rename the columns and then re-order the dataframe, but is there a more elegant way?
df1 <- data.frame(
testcase = c('testcase1', 'testcase2', 'testcase3', 'testcase4', 'testcase5'),
passed = c('2', '0', '2', '0', '0'),
failed = c('0', '2', '2', '0', '2'))
df2 <- data.frame(
id = c(1:10), testid = c('testcase3', 'testcase1', 'testcase3', 'testcase2', 'testcase5', 'testcase1',
'testcase3', 'testcase5', 'testcase2', 'testcase3'), total_passed = rep("", 10), total_failed= rep("", 10), testid = c(510:519), total_items = rep("", 10))
My solution would be the following, but could it be done with less steps?
df3 <- merge(df2, df1, by.x='testid', by.y='testcase')
df3$total_passed <- df3$total_failed <- NULL
df3$total_items <- 10
df3 <- select(df3, id, testid, total_passed = passed, total_failed= failed, testid, total_items)