处理特定国家的数据。需要将国家分配和分组到预定义的国家组中。编写代码如下。想知道是否有更有效的脚本编写方法,每次进入数据库时不输入每个新国家到分配到非核心组的部分?听起来像如果其他。但不知道如何编码。
library(data.table)
data<- data.table(data)
setkey(data,Region.Group)
data[list(c(
"Australia",
"Bangladesh",
"Cambodia",
"Estonia",
"Finland",
"France",
"India",
"Indonesia",
"Korea",
"Lithuania",
"Malaysia",
"Middle East",
"Norway",
"Philippines",
"Poland",
"Russia",
"Spain",
"Sri Lanka",
"Sweden",
"Switzerland",
"TAT Region",
"Thailand",
"Ukraine",
"Vietnam",
"New Zealand",
"Israel",
"Myanmar",
"Pakistan",
"Portugal",
"Turkey",
"Portugal")), Core:="NON-CORE"]
data[list(c(
"Belgium",
"Netherlands")), Core:="Benelux"]
data[list(c(
"China Group")), Core:="China"]
data[list(c(
"Germany")), Core:="Germany"]
data[list(c(
"Hong Kong Group")), Core:="Hong Kong"]
data[list(c(
"Italy")), Core:="Italy"]
data[list(c(
"Japan")), Core:="Japan"]
data[list(c(
"North America Central",
"North America East",
"North America North",
"North America South",
"North America West")), Core:="N.America"]
data[list(c(
"Singapore")), Core:="Singapore"]
data[list(c(
"Taiwan")), Core:="Taiwan"]
data[list(c(
"United Kingdom")), Core:="UK"]