Reputation: 373
I want to rename column data.
for example
I have under dataset.
change_name <- data.frame(org_name = c("a", "b", "c"), new_name = c("A", "B", "C"))
dt <- data.frame(name = c("a", "b", "c"), data = c(1, 2, 3))
dt
dataset column name
change using change_name
dataset
and want to get like the under dataset.
dt <- data.frame(name = c("A", "B", "C"), data = c(1, 2, 3))
Upvotes: 0
Views: 63
Reputation: 373
I resolve the problem use under the code, too.
dt$name <-
plyr::mapvalues(dt$name, change_name$org_name, change_name$new_name
Upvotes: 0
Reputation: 887118
We can use match
dt$name <- change_name$new_name[match(dt$name, change_name$org_name)]
Upvotes: 1