当前位置:网站首页>R 16 basic exercises
R 16 basic exercises
2022-06-11 20:08:00 【THE ORDER】
> rnorm(4)
[1] -0.7074952 0.3645820 0.7685329 -0.1123462
> set.seed(10)# Seed a fixed random number , Random numbers with the same seed have certain same rules
> rnorm(4)
[1] 0.01874617 -0.18425254 -1.37133055 -0.59916772
> set.seed(12)
> rnorm(3)
[1] -1.4805676 1.5771695 -0.9567445
> runif(3)
[1] 0.17878500 0.64166537 0.02287774
> rnorm(3)
[1] -2.3943544 0.8922874 -0.3033484
> set.seed(12)
> rnorm(3)
[1] -1.4805676 1.5771695 -0.9567445
> runif(3)
[1] 0.17878500 0.64166537 0.02287774
> rnorm(3)
[1] -2.3943544 0.8922874 -0.3033484
> sample(1:10,4)
[1] 9 6 4 2
> sample(1:10,8,replace=T)
[1] 10 7 8 4 8 9 8 10
> sample(letters,10,replace = T)
[1] "k" "n" "g" "l" "e" "y" "b" "g" "n" "g"
> sample(1:10)
[1] 10 4 9 3 8 6 1 5 2 7
> x=airquality# Data frame
> index=sample(1:nrow(x),nrow(x)*0.7)# Random sampling line number
> train=x[index,]# Get the training set
> test=x[-index,]# Get the test set
> rep(1:3,4)# Create duplicates
[1] 1 2 3 1 2 3 1 2 3 1 2 3
> rep(1:3,each=4)# repeat 4 Repeat the next number again 4 Time
[1] 1 1 1 1 2 2 2 2 3 3 3 3
> rep(c("a","b"),each=2,times=3)
[1] "a" "a" "b" "b" "a" "a" "b" "b" "a" "a" "b" "b"
> seq(-10,10,2)# A sequence of equal differences
[1] -10 -8 -6 -4 -2 0 2 4 6 8 10
> seq(-10,by=3,length.out=10)
[1] -10 -7 -4 -1 2 5 8 11 14 17
> sequence(3:5)# Sequential 3-5
[1] 1 2 3 1 2 3 4 1 2 3 4 5
> rn=rnorm(100,mean = 5,sd=2)# establish 100 The average number is 5, The standard deviation is 2 Positive distribution random number
> lt=sample(letters,100,replace = T)#100 Random English letters , Put it back
> sa=sample(1:10,100,replace=T)#1-10,100 A random number , Put it back
> rp=rep(1:5,each=2,times=10)# Create duplicates 1:5,1122334455,10 Time
> se=seq(0,49.5,0.5)# establish 0-49.5 The difference is 0.5 Equal difference sequence of
> a=data.frame(rn,lt,sa,rp,se)# Create a data frame
> a
rn lt sa rp se
1 3.8970845 z 3 1 0.0
2 5.2141178 w 5 1 0.5
3 6.5782481 n 6 2 1.0
4 4.5114894 v 10 2 1.5
5 5.7683599 a 9 3 2.0
6 2.6615290 x 3 3 2.5
7 8.0365449 u 9 4 3.0
8 5.1459624 a 4 4 3.5
9 3.9446499 c 2 5 4.0
10 3.9509488 c 1 5 4.5
11 6.4938015 a 7 1 5.0
12 2.6351721 d 5 1 5.5
13 2.2905830 w 1 2 6.0
14 4.5754290 k 8 2 6.5
15 4.8210370 i 7 3 7.0
16 5.5140650 t 10 3 7.5
17 7.4085737 g 4 4 8.0
18 4.6519378 x 3 4 8.5
19 6.3804336 l 7 5 9.0
20 5.8267692 q 3 5 9.5
21 2.1390419 q 8 1 10.0
22 2.4006618 j 2 1 10.5
23 7.8066997 m 8 2 11.0
24 4.5612996 y 10 2 11.5
25 9.2649822 a 7 3 12.0
26 1.3330602 u 8 3 12.5
27 4.7789806 a 8 4 13.0
28 6.5314207 w 8 4 13.5
29 5.6470092 g 2 5 14.0
30 3.5292422 p 6 5 14.5
31 7.2914343 h 3 1 15.0
32 4.4435251 n 10 1 15.5
33 7.1136826 l 4 2 16.0
34 5.7350289 s 9 2 16.5
35 6.6950292 q 2 3 17.0
36 2.4743591 z 9 3 17.5
37 6.0564733 w 8 4 18.0
38 7.1788136 o 8 4 18.5
39 3.6010433 s 6 5 19.0
40 7.8420523 d 4 5 19.5
41 7.8780434 l 5 1 20.0
42 2.4093774 y 2 1 20.5
43 3.2058803 p 9 2 21.0
44 1.2304478 g 8 2 21.5
45 5.0549958 n 9 3 22.0
46 3.1851667 a 10 3 22.5
47 1.7048766 d 8 4 23.0
48 5.5046801 p 4 4 23.5
49 6.2846285 y 7 5 24.0
50 4.3061278 k 7 5 24.5
51 3.9694735 v 8 1 25.0
52 5.7963378 j 5 1 25.5
53 6.9071144 k 5 2 26.0
54 5.5203578 r 10 2 26.5
55 0.8997312 u 1 3 27.0
56 5.5759414 i 7 3 27.5
57 5.7238908 w 3 4 28.0
58 1.6265180 u 2 4 28.5
59 7.4943396 u 10 5 29.0
60 1.4596142 a 1 5 29.5
61 5.4456717 b 2 1 30.0
62 3.8789591 q 9 1 30.5
63 3.9837409 q 1 2 31.0
64 3.1223338 i 7 2 31.5
65 8.2712988 l 1 3 32.0
66 3.6943662 d 7 3 32.5
67 6.6784272 e 10 4 33.0
68 3.7768094 d 4 4 33.5
69 4.2565661 t 8 5 34.0
70 3.9695321 u 9 5 34.5
71 4.3164628 r 4 1 35.0
72 6.3678376 r 4 1 35.5
73 6.5966849 b 3 2 36.0
74 3.4003917 o 5 2 36.5
75 5.4592605 l 2 3 37.0
76 8.3870959 z 3 3 37.5
77 3.4630581 d 1 4 38.0
78 1.9136946 z 3 4 38.5
79 2.3587982 g 4 5 39.0
80 3.6483570 x 1 5 39.5
81 4.2659891 m 6 1 40.0
82 3.9722556 n 7 1 40.5
83 3.0814921 u 3 2 41.0
84 4.7566727 h 10 2 41.5
85 6.3318743 f 9 3 42.0
86 7.4774396 q 8 3 42.5
87 7.3678816 v 5 4 43.0
88 7.9967230 w 3 4 43.5
89 4.4217913 k 10 5 44.0
90 8.8473744 g 6 5 44.5
91 6.0370249 f 9 1 45.0
92 5.9531819 h 3 1 45.5
93 5.6052075 r 7 2 46.0
94 6.6424654 v 4 2 46.5
95 5.7851585 g 5 3 47.0
96 2.1190982 s 4 3 47.5
97 3.2622050 m 1 4 48.0
98 -0.9729121 a 9 4 48.5
99 4.8989054 d 5 5 49.0
100 7.5990258 z 6 5 49.5
> r1=mean(rn)# The average
> r2=sd(rn)# Standard deviation
> r3=var(rn)# variance
> r4=median(rn)# Median
> r5=sum(rn)# Sum up
> rowMeans(a[,-2])# Row average
[1] 1.974271 2.928529 3.894562 4.502872 4.942090 2.790382 6.009136 4.161491 3.736162 3.612737 4.873450 3.533793 2.822646
[14] 5.268857 5.455259 6.503516 5.852143 5.037984 6.845108 5.831692 5.284760 3.975165 7.201675 7.015325 7.816246 6.208265
[27] 7.444745 8.007855 6.661752 7.257311 6.572859 7.735881 7.278421 8.308757 7.173757 7.993590 9.014118 9.419703 8.400261
[40] 9.085513 8.469511 6.477344 8.801470 8.182612 9.763749 9.671292 9.176219 9.251170 10.571157 10.201532 9.492368 9.324084
[53] 9.976779 11.005089 7.974933 10.768985 10.180973 9.031629 12.873585 9.239904 9.611418 11.094740 9.495935 10.905583 11.067825
[66] 11.548592 13.419607 11.319202 12.814142 13.117383 11.079116 11.716959 11.899171 11.725098 11.864815 12.971774 11.615765 11.853424
[79] 12.589700 12.287089 12.816497 13.118064 12.270373 14.564168 15.082969 15.244360 14.841970 14.624181 15.855448 16.086844 15.259256
[92] 13.863295 15.151302 14.785616 15.196290 14.154775 14.065551 15.131772 15.974726 17.024756
> colSums(a[,-2])# Column sum
rn sa rp se
490.9063 566.0000 300.0000 2475.0000
> a$logrn=log(a$rn)# The new column takes logarithm
Warning message:
In log(a$rn) : NaNs produced
> a
rn lt sa rp se logrn
1 3.8970845 z 3 1 0.0 1.3602287
2 5.2141178 w 5 1 0.5 1.6513699
3 6.5782481 n 6 2 1.0 1.8837685
4 4.5114894 v 10 2 1.5 1.5066273
5 5.7683599 a 9 3 2.0 1.7523878
6 2.6615290 x 3 3 2.5 0.9789008
7 8.0365449 u 9 4 3.0 2.0839992
8 5.1459624 a 4 4 3.5 1.6382124
9 3.9446499 c 2 5 4.0 1.3723602
10 3.9509488 c 1 5 4.5 1.3739558
11 6.4938015 a 7 1 5.0 1.8708481
12 2.6351721 d 5 1 5.5 0.9689485
13 2.2905830 w 1 2 6.0 0.8288064
14 4.5754290 k 8 2 6.5 1.5207005
15 4.8210370 i 7 3 7.0 1.5729891
16 5.5140650 t 10 3 7.5 1.7073021
17 7.4085737 g 4 4 8.0 2.0026379
18 4.6519378 x 3 4 8.5 1.5372839
19 6.3804336 l 7 5 9.0 1.8532361
20 5.8267692 q 3 5 9.5 1.7624627
21 2.1390419 q 8 1 10.0 0.7603580
22 2.4006618 j 2 1 10.5 0.8757444
23 7.8066997 m 8 2 11.0 2.0549823
24 4.5612996 y 10 2 11.5 1.5176076
25 9.2649822 a 7 3 12.0 2.2262419
26 1.3330602 u 8 3 12.5 0.2874772
27 4.7789806 a 8 4 13.0 1.5642273
28 6.5314207 w 8 4 13.5 1.8766245
29 5.6470092 g 2 5 14.0 1.7311261
30 3.5292422 p 6 5 14.5 1.2610832
31 7.2914343 h 3 1 15.0 1.9867003
32 4.4435251 n 10 1 15.5 1.4914480
33 7.1136826 l 4 2 16.0 1.9620201
34 5.7350289 s 9 2 16.5 1.7465928
35 6.6950292 q 2 3 17.0 1.9013653
36 2.4743591 z 9 3 17.5 0.9059814
37 6.0564733 w 8 4 18.0 1.8011277
38 7.1788136 o 8 4 18.5 1.9711341
39 3.6010433 s 6 5 19.0 1.2812236
40 7.8420523 d 4 5 19.5 2.0595006
41 7.8780434 l 5 1 20.0 2.0640796
42 2.4093774 y 2 1 20.5 0.8793684
43 3.2058803 p 9 2 21.0 1.1649867
44 1.2304478 g 8 2 21.5 0.2073781
45 5.0549958 n 9 3 22.0 1.6203770
46 3.1851667 a 10 3 22.5 1.1585046
47 1.7048766 d 8 4 23.0 0.5334927
48 5.5046801 p 4 4 23.5 1.7055987
49 6.2846285 y 7 5 24.0 1.8381067
50 4.3061278 k 7 5 24.5 1.4600391
51 3.9694735 v 8 1 25.0 1.3786335
52 5.7963378 j 5 1 25.5 1.7572263
53 6.9071144 k 5 2 26.0 1.9325520
54 5.5203578 r 10 2 26.5 1.7084427
55 0.8997312 u 1 3 27.0 -0.1056592
56 5.5759414 i 7 3 27.5 1.7184612
57 5.7238908 w 3 4 28.0 1.7446488
58 1.6265180 u 2 4 28.5 0.4864415
59 7.4943396 u 10 5 29.0 2.0141480
60 1.4596142 a 1 5 29.5 0.3781722
61 5.4456717 b 2 1 30.0 1.6948211
62 3.8789591 q 9 1 30.5 1.3555669
63 3.9837409 q 1 2 31.0 1.3822213
64 3.1223338 i 7 2 31.5 1.1385807
65 8.2712988 l 1 3 32.0 2.1127915
66 3.6943662 d 7 3 32.5 1.3068090
67 6.6784272 e 10 4 33.0 1.8988825
68 3.7768094 d 4 4 33.5 1.3288796
69 4.2565661 t 8 5 34.0 1.4484627
70 3.9695321 u 9 5 34.5 1.3786482
71 4.3164628 r 4 1 35.0 1.4624363
72 6.3678376 r 4 1 35.5 1.8512599
73 6.5966849 b 3 2 36.0 1.8865672
74 3.4003917 o 5 2 36.5 1.2238906
75 5.4592605 l 2 3 37.0 1.6973133
76 8.3870959 z 3 3 37.5 2.1266943
77 3.4630581 d 1 4 38.0 1.2421520
78 1.9136946 z 3 4 38.5 0.6490357
79 2.3587982 g 4 5 39.0 0.8581522
80 3.6483570 x 1 5 39.5 1.2942769
81 4.2659891 m 6 1 40.0 1.4506741
82 3.9722556 n 7 1 40.5 1.3793341
83 3.0814921 u 3 2 41.0 1.1254139
84 4.7566727 h 10 2 41.5 1.5595484
85 6.3318743 f 9 3 42.0 1.8455963
86 7.4774396 q 8 3 42.5 2.0118904
87 7.3678816 v 5 4 43.0 1.9971302
88 7.9967230 w 3 4 43.5 2.0790318
89 4.4217913 k 10 5 44.0 1.4865449
90 8.8473744 g 6 5 44.5 2.1801207
91 6.0370249 f 9 1 45.0 1.7979113
92 5.9531819 h 3 1 45.5 1.7839259
93 5.6052075 r 7 2 46.0 1.7236961
94 6.6424654 v 4 2 46.5 1.8934832
95 5.7851585 g 5 3 47.0 1.7552958
96 2.1190982 s 4 3 47.5 0.7509906
97 3.2622050 m 1 4 48.0 1.1824034
98 -0.9729121 a 9 4 48.5 NaN
99 4.8989054 d 5 5 49.0 1.5890118
100 7.5990258 z 6 5 49.5 2.0280200
边栏推荐
- MySQL——基本的Select语句
- Skywalking source code analysis Part 5 - server configuration configuration module startup
- First modelarts training
- Simulate Oracle lock waiting and manual unlocking
- Leetcode 1992. Find all farm groups (yes, once)
- Course design for construction organization, School of distance and continuing education, Dalian University of technology [standard answer]
- 干货!基于序列超图神经网络的信息扩散预测
- Experiment report of basic mechanical experiment (II) of School of distance and continuing education, Dalian University of technology [standard answer]
- Linux环境安装mysql数据库详细教程(含卸载和密码重置过程)
- [bug resolution] unpickingerror: a load persistent ID instruction was encoded, but no persistent_ load.
猜你喜欢

Explanation of LNMP architecture source code compilation and installation with pictures and texts (with forum experiment)

Interpretation of OCP function of oceanbase Community Edition

In 2021, the global revenue of flexible fireproof sealant is about 755.2 million dollars, and it is expected to reach 1211.7 million dollars in 2028

Detailed tutorial on installing MySQL database in Linux environment (including uninstallation and password reset process)

Modelarts second job

3D建模有什么技巧吗?

28. JS执行机制

Rtd2171u, substitute for trd2171u, substitute for trd2171u, cs5261 C to hdmi4k_ 30Hz

In 2021, the global ceramic substrate revenue will be about US $409.7 million, and it is expected to reach US $657.3 million in 2028

A brief talk on shutter button
随机推荐
[Err] 1045 - Access denied for user ‘root‘@‘%‘ (using password: YES)
【四川大学】初试复试考研资料分享
Xmake help 2
C deep copy
2022Redis7.0x版本持久化详细讲解
Using the flask framework to write the bezel
Power supply anti reverse connection and anti backflow - use MOS tube and op amp to realize ideal diode
2022-2028 current situation and future development trend of fuel cell market for cogeneration application in the world and China
In 2021, the global adult diaper revenue was about $11560million, which is expected to reach $15440million in 2028. From 2022 to 2028, the CAGR was 4.2%
27. this pointing problem
巴比特 | 元宇宙每日必读:数字藏品二级市场乱象丛生,00后成新韭菜,监管迫在眉睫?...
2022-2028 global and Chinese thermal power generation (TEG) module market status and future development trend
【mysql进阶】10种数据类型的区别以及如何优化表结构(三)
Calculation of Zeno paradox
WR | 西湖大学鞠峰组微纳塑料污染对人工湿地菌群与脱氮功能的影响
Flutter doctor 显示xcode没有安装的解决办法
Usage methods and cases of PLSQL blocks, cursors, functions, stored procedures and triggers of Oracle Database
"Video version Mae" of hekaiming team, efficient video pre training! The effect is also very good when mask ratio is up to 90
Simulate Oracle lock waiting and manual unlocking
Proficient in xmake