Suppose I have a dataset in R with variables named dog cat and cow. Then there are some number of values under each variable (ie. each is =1 if the respondent owns one and =0 if they don't):
household_ID dog cat cow
00001 0 1 1
00002 1 0 1
00003 0 0 0
Suppose I have another dataset where one column contains my current variables, and another column contains new variable names such that each row contains the new name that should replace the old name:
oldname newname
dog canine
cat feline
cow bovine
My goal in this oversimplified example is to replace the variable names of the first dataset using the second dataset. I'm imagining some kind of loop where you replace var = newname if var = oldname but I can't get the syntax right and I'm a little stumped. Here's what I'm hypothetically after:
household_ID canine feline bovine
00001 0 1 1
00002 1 0 1
00003 0 0 0