In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Most people do not understand the knowledge points of this article "how to use the scale () function of R language", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use the scale () function of R language" article.
R language scale function, can deal with data, standardization (normalization) in a certain range, more suitable for a wide range of data normalization processing to observe the data change trend scale () function scale (x, center = TRUE, scale = TRUE) x general.
R language scale function, can process the data, standardization (normalization) in a certain range, more suitable for large-scale data normalization processing in order to observe the trend of data change
Scale () function
Scale (x, center = TRUE, scale = TRUE)
X is usually a matrix or a numerical vector.
Whether center-- is centralized or not
Is scale-- standardized?
1. Take the numerical vector as an example:
> A [1] 3.74149 7.36180 5.81734 5.71131 7.97054 10.37620 6.29949 5.55062 5.84779 [10] 15.58810 14.76360 17.74670
Length: 12 ~ (th) scaleplate T ~ (th) centerpiece T:
> scaleA=scale (A) > scaleA [, 1] [1,]-1.1123845 [2,]-0.3313828 [3,]-0.6645658 [4,]-0.6874395 [5,]-0.2000606 [6,] 0.3189073 [7,]-0.5605527 [8]-0.7221048 [9,]-0.6579969 [10,] 1.4432593 [11,] 1.2653916 [12,] 1.9089294attr ( "scaled:center") [1] 8.897915attr (, "scaled:scale") [1] 4.63547 >
The length is 12 minutes scalenumbers, and the numbers are all positive.
> scaleA=scale [, 1] [1] [1,] 0.3602619 [2,] 0.7088557 [3,] 0.5601421 [4,] 0.5499327 [5,] 0.7674702 [6,] 0.9991073 [7,] 0.6065676 [8,] 0.5344601 [9] 0.5630741 [10,] 1.5009526 [11,] 1.4215629 [12,] 1.7088007attr (, "scaled:scale") [1] 10.38547
Note: the values cannot be exactly the same, otherwise NaN is returned:
> scale [, 1] [1,] NaN [2,] NaN [3,] NaN [4,] NaN [5,] NaN [6,] NaNattr (, "scaled:center") [1] 1attr (, "scaled:scale") [1] 0
2. Take the numerical matrix as an example: the scale result of each column is calculated (the first column data happens to be the demonstration data of the previous step, so you can compare the results)
> dat1 A B C D E F G H I J K LCK-WT-1 3.74149 5.23528 2.821317 118.6600 1.8737693 1.7103460 30.26110 86.6405 1448.6278 173.9960 77.06166 3.19210CK-WT-2 7.36180 2.77070 1.563395 140.1430 16.9090246 0.7802436 33.65711 116.4700 1634.0417 51.0019 98.30970 4.69276CK-WT-3 5.81734 2.66859 1.931628 123.3830 0.9559375 2.7996091 31.46691 111.7380 1566.5626 52.3322 101.42702 3.58136CK-tdr1-1 5.71131 3.22632 3.194809 97.2229 0.4774184 4.7297117 30.96890 82.8809 648.4734 66.9486 46.86340 3.03234CK-tdr1-2 7.97054 1.32105 2.600854 95.2539 0. 5273923 4.3637146 28.03340 85.7292 683.4113 41.1148 70.29293 2.11160CK-tdr1-3 10.37620 1.96726 2.301278 91.8525 0.4333881 3.3732144 27.62150 79.6027 647.2750 49.7169 57.09809 3.53808NaWT-1 6.29949 2.40259 2.044360 121.8080 39.1065780 2.27835571 106.4650 1248.4062 192.7300 151.37454 4.79151NaWT-2 5.55062 3.23077 2.104095 125.1350 36. 5302500 2.8043996 32.99440 111.3370 1117.6042 183.2700 160.54078 4.16132NaWT-3 5.84779 4.80378 2.630611 106.5070 19.4561309 2.9542534 32.77111 98.1677 1191.6926 111.2120 137.35694 3.40994Natdr1-1 15.58810 2.04301 2.289544 81.6997 13.2227038 3.1700429 19.02370 69.4519 501.2779 78.8024 101.08433 6.01932Natdr1-2 14.76360 2.29524 2.801336 84.8495 10.88977804.6643058 18.14860 69.7807 395.9033 96.2520 82.21420 5.59169Natdr1-3 17.74670 1.95286 2.450605 80.3895 12.2580100 4.0243357 15.7998068.8929 468.8953 66.7984 108.79391 8.12127
The length of each column is 12 scaleblocks, which returns the matrix after scale.
> scaleDat1 A B C D E F G H I J KCK-WT-1-1.1123845 2.06922600 0.9498394 0.65959663-0.79734415-1.19085395 0.3345230824-0.2241247 1.0711933 1.37750741-0.62155046CK-WT-2-0 . 3313828-0.04789386-1.8494507 1.74255232 0.30794653-1.96684043 0.8433687097 1.4659006 1.4799090-0.82335259-0.02949209CK-WT-3-0.6645658-0.13560824-1.0300104 0.89768254-0.86481696-0.28207930 0.5151965742 1.1978036 1.3311618-0.79954817 0.05736930CK-tdr1-1-0.6874395 0.349216 1.7809813-0.42104526-0.89999446 1.32820957 0.4405772141-0.4371293-0.6926209-0. 53800188-1.46299915CK-tdr1-2-0.2000606-1.29317006 0.4592366-0.52030233-0.89632071 1.02285734 0.0007314704-0.2757555-0.6156058-1.00027265-0.81015531CK-tdr1-3 0.3189073-0.73806370-0.2074192-0.69176654-0.90323127 0.19648085-0.0609863755-0.6228596-0.6952627-0.84634642-1.17781819NaWT-1-0.5605527-0.36410717-0.7791451 0.81828696 1.93976112-0 .71696069 1.1338423951 0.8990556 0.6298363 1.71273416 1.44911408NaWT-2-0.7221048 0.34731479-0.6462152 0.98600067 1.75036684-0.27808262 0.7440715578 1.1750845 0.3415040 1.54345664 1.70452348NaWT-3-0.6579969 1.69855951 0.5254554 0.04696522 0.495192 63-0.15305922 0.7106135334 0.4289623 0.5048200 0.25404869 1.05852570Natdr1-1.4432593-0.67299305-0.2335303-1.20356808 0.03695307 0.02697441 -1.3492524881-1.1979651-1.0170902-0.32588964 0.04782059Natdr1-2 1.2653916-0.45632281 0.9053748-1.04478701-0.13454792 1.27364125-1.4803744502-1.1793365-1.2493721-0.01364599-0.47797937Natdr1-3 1.9089294-0.75043357 0.1248833-1.26961512-0.03396473 0.73971279-1.8323112232-1.2296359-1.0884727-0.54068956 0.26264141 LCK-WT-1 -0.7138772CK-WT-2 0.2084474CK-WT-3-0.4746331CK-tdr1-1-0.8120677CK-tdr1-2-1.3779661CK-tdr1-3-0.5012335NaWT-1 0.2691404NaWT-2-0.1181823NaWT-3-0.5799900Natdr1-1 1.0237679Natdr1-2 0.7609411Natdr1-3 2.3156530attr ( "scaled:center") A B C D E F G H I J K L 8.897915 2.826454 2.394486 105.575333 12.720032 3.137711 28.028521 90.596375 962.680951 97.014600 99.368125 4.353607 attr ( "scaled:scale") A B C D E F G H I J K 4.6354700 1.1641193 0.4493719 19.8373766 13.6029875 1.1986064 6.6739314 17.6503265 453.6500351 55.8845631 35.8884205 L 1.6270411
3. The matrix is huge, or you can specify rows or columns to standardize, which can be carried out in batches with apply, such as the matrix of 12X2000 (the structure is similar to the previous step):
> dim (dat2) [1] 12 2000
By default, you can directly scale (dat2) to get the column results, and the returned results are the same as the second step. What if you specify the row results?
CK-WT-1 CK-WT-2 CK-WT-3 CK-tdr1-1 CK-tdr1-2 CK-tdr1-3 NaWT-1 NaWT-2 NaWT-3 Natdr1-1 Natdr1-2 Natdr1-3AT1G01010-0.2386968-0.2245197-0.2270909-0.2677180-0.2599348-0.2392684-0.2021240-0.2093897-0.2163308-0.1800695-0.1880828-0.1720898AT1G01030-0.2322447-0.2436961-0.2411622- 0.2852821-0.3091559-0.2995012-0.2159012-0.2178163-0.2205802-0.2509797-0.2544241-0.2586433 AT1G01010 AT1G01030 AT1G01040 AT1G01050 AT1G01060 AT1G01070 AT1G01080 AT1G01090 AT1G01100 AT1G01120-0.2386968-0.2322447-0.2426714 0.2576744-0.2467641-0.2474700-0.1241498 0.1193716 6.0022478 0.4966890
Note that the specified row, that is, apply (dat2,1,scale), in 1, the return result will be a large matrix, scale the row, which is equivalent to processing 2000 data many times, returning the matrix structure and the situation of column transposition of the original matrix, that is to say: the result of row processing appears in the column of the return value.
For example, after the above processing, the return value of the first row is the first column of ScaleDat2_row, and the first ten of them are shown above. The first 10 return values for dat2 [1,] processing are as follows (both are consistent):
Note: directly take the first column scale (dat2 [1,] will return NaN, which needs to be converted to pure numerical vector as.numeric first.
> Row1=dat2 [1,] > scale (as.numeric (Row1)) [1:10] [1]-0.2386968-0.2322447-0.2426714 0.2576744-0.2467641-0.2474700-0.1241498 0.1193716 6.0022478 0.4966890 above is about the content of this article "how to use scale () function in R language". I believe everyone has a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about it, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.