2015-04-03 68 views
0

IS1设置比例转换中的R

0 
0.06 
-0.58 
-0.87 
-1 
-0.77 
-1 
-0.62 
0.83 
-0.86 
-0.83 
0.42 
-0.6 
1 
0.47 
0.94 
0.23 
0.46 
-0.98 
-0.04 
-0.39 
0.99 
0.81 
0.11 
-0.85 
-0.56 
0.14 
1 
-0.79 
-0.06 
-0.58 
0.79 
0.71 
-0.2 
0.69 
-0.33 
0.64 
-0.76 
0.14 
-0.41 
1 
-0.83 
0.01 
-0.86 
-0.65 
-0.58 
0.5 
-0.39 
-0.8 
-0.36 
0.17 
-0.96 
-0.46 
-0.78 

我的数据集是这样的,现在我怎么了规模0.1转换为1?

+0

@akrun:我没有得到你?它的范围从 - 1到+1 – 2015-04-03 05:25:46

+0

你在'plotrix'包中有'rescale'。另请http://stats.stackexchange.com/a/25897 – 2015-04-03 05:30:58

回答

1
is1 <- c(0, 0.06, -0.58, -0.87, -1, -0.77, -1, -0.62, 0.83, -0.86, -0.83, 
     0.42, -0.6, 1, 0.47, 0.94, 0.23, 0.46, -0.98, -0.04, -0.39, 
     0.99, 0.81, 0.11, -0.85, -0.56, 0.14, 1, -0.79, -0.06, -0.58, 
     0.79, 0.71, -0.2, 0.69, -0.33, 0.64, -0.76, 0.14, -0.41, 1, 
     -0.83, 0.01, -0.86, -0.65, -0.58, 0.5, -0.39, -0.8, -0.36, 0.17, 
     -0.96, -0.46, -0.78) 

nmin <- 0.1 
nmax <- 1 

plotrix包使用rescale功能:

library(plotrix) 
res1 <- rescale(is1, c(nmin, nmax)) 
head(res1) 
# [1] 0.5500 0.5770 0.2890 0.1585 0.1000 0.2035 
range(res1) 
# [1] 0.1 1.0 

或从本answer

res2 <- (nmax-nmin)/(max(is1)-min(is1)) * (is1-min(is1)) + nmin 
head(res2) 
# [1] 0.5500 0.5770 0.2890 0.1585 0.1000 0.2035 
range(res2) 
# [1] 0.1 1.0