我想将一列中的某些值除以一个数字,然后将该值存储在另一列中。在R

我想将一列中的某些值除以一个数字,然后将该值存储在另一列中。在R,r,data-wrangling,R,Data Wrangling,这就是我正在做的: enter code here nw_dat$cost_of_2_AUD<-if ( nw_dat$Country=="India") { nw_dat$cost_of_2_AUD <- nw_dat$Average.Cost.for.two/56.7 } else if (nw_dat$Country=="Phillipines") { nw_dat$cost_of_2_AUD <- nw_dat$Average.

这就是我正在做的:

enter code here
nw_dat$cost_of_2_AUD<-if ( nw_dat$Country=="India") {
nw_dat$cost_of_2_AUD <- nw_dat$Average.Cost.for.two/56.7
} else if (nw_dat$Country=="Phillipines") {
 nw_dat$cost_of_2_AUD <- nw_dat$Average.Cost.for.two/36.97
} else if ( nw_dat$Country=="Brazil") {
  nw_dat$cost_of_2_AUD <- nw_dat$Average.Cost.for.two/4.08
}else if ( nw_dat$Country=="Canada") {
nw_dat$cost_of_2_AUD <- nw_dat$Average.Cost.for.two/0.94
}else if ( nw_dat$Country=="Indonesia") {
nw_dat$cost_of_2_AUD <- nw_dat$Average.Cost.for.two/11066.12
}else if ( nw_dat$Country=="New Zealand") {
nw_dat$cost_of_2_AUD <- nw_dat$Average.Cost.for.two/1.08
}else if ( nw_dat$Country=="Singapore") {
nw_dat$cost_of_2_AUD <- nw_dat$Average.Cost.for.two/1.03
}else if ( nw_dat$Country=="South Africa") {
nw_dat$cost_of_2_AUD <- nw_dat$Average.Cost.for.two/10.92
}else if ( nw_dat$Country=="Sri Lanka") {
nw_dat$cost_of_2_AUD <- nw_dat$Average.Cost.for.two/152.35
}else if ( nw_dat$Country=="Turkey") {
nw_dat$cost_of_2_AUD <- nw_dat$Average.Cost.for.two/6.57
}else if ( nw_dat$Country=="UAE") {
 nw_dat$cost_of_2_AUD <- nw_dat$Average.Cost.for.two/2.84
}else if ( nw_dat$Country=="United Kingdom") {
 nw_dat$cost_of_2_AUD <- nw_dat$Average.Cost.for.two/0.55
}else if ( nw_dat$Country=="United States") {
  nw_dat$cost_of_2_AUD <- nw_dat$Average.Cost.for.two/0.77
}else {
  nw_dat$cost_of_2_AUD <- nw_dat$Average.Cost.for.two
在此处输入代码

nw_dat$cost_of_2_AUD创建一个包含国家名称和相应值的查找表,以便为该国家划分

#Include all the countries, I am showing only 3 as example. 
lookup <- data.frame(Country = c('India', 'Phillipines', 'Brazil'), 
                     value = c(56.7, 36.97, 4.08))

如果您创建一个小的可复制的示例以及预期的输出,那么会更容易提供帮助。了解。图像不是共享数据/代码的正确方式。
nw_dat <- transform(merge(nw_dat, lookup, by = 'Country'), 
                    cost_of_2_AUD = Average.Cost.for.two/value)