I have a data frame like below and have millions of records, so I want to add column for total_score and expected_score. If region1
has "all region" then add columns t_all_region
, t_east
, t_west
and add values from total_score
.
so here we have 3 regions then create three columns t_all_region
, t_east
, t_west
and add values from total_score
Same needed to do for expected_score
.
df <- data.frame(total_score=c(4.5,12.2,4.6,9.2,12.2,36.4),
expected_score=c(4.5,12.1,NA,9.2,12.2,NA),
Region1=c("All region",NA,NA,"All region","All region",NA),
Region2=c("EAST","EAST","EAST","EAST","EAST",NA),
Region3=c("West",NA,"West","West","West","West"))