Questions
1. Simulate data for 30 draws from a normal distribution where the means and standard deviations vary among three distributions.
set.seed(10)
rnorm(30,mean=c(2,6,100),sd=c(1,10,50))
## [1] 2.0187462 4.1574746 31.4334725 1.4008323 8.9454513
## [6] 119.4897150 0.7919238 2.3632398 18.6663659 1.7435216
## [11] 17.0177950 137.7890754 1.7617664 15.8744470 137.0695064
## [16] 2.0893473 -3.5494386 90.2424808 2.9255213 10.8297852
## [21] 70.1844682 -0.1852868 -0.7486594 -5.9530596 0.7348020
## [26] 2.2633844 65.6222285 1.1278412 4.9823899 87.3109735
2. Simulate 2 continuous variables (normal distribution) (n=20) and plot the relationship between them
set.seed(5)
x=rnorm(20,mean=2,sd=6)
set.seed(7)
y=rnorm(20,mean=8,sd=10)
plot(y~x)

4. Simulate 3 letters repeating each letter twice, 2 times.
rep(letters[3:5],each=2,times=2)
## [1] "c" "c" "d" "d" "e" "e" "c" "c" "d" "d" "e" "e"
5. Create a dataframe (n = 27) with 3 groups, 2 factors and two quantitative response variables. Use the replicate function.
DFgenReplicated=replicate(3, expr=(data.frame(group=rep(letters[1:3], each=9),factor=rep(letters[4:5], length.out=27),
x=rnorm(27,0,1),y=rnorm(27,1,2))), simplify=FALSE)
DFgenReplicated
## [[1]]
## group factor x y
## 1 a d -1.09073015 1.34413320
## 2 a e -0.65725422 1.24098634
## 3 a d 2.26294100 2.11506534
## 4 a e 0.08769003 1.98276632
## 5 a d 0.76752300 0.86197475
## 6 a e -0.61315746 -1.70159263
## 7 a d 0.15250297 2.59871514
## 8 a e -0.59170745 0.35981185
## 9 a d -0.96070497 0.28609762
## 10 b e -0.58495799 -0.02145588
## 11 b d 0.65667289 -2.75776016
## 12 b e -0.29024959 -0.90369018
## 13 b d 0.90409773 5.54631323
## 14 b e 0.19902022 1.40537526
## 15 b d -0.05157481 -3.61710940
## 16 b e -0.90820518 0.88672867
## 17 b d -1.14247834 1.12568768
## 18 b e 0.99032494 2.42045627
## 19 c d 0.11227328 -0.18461479
## 20 c e 1.14963167 1.59704926
## 21 c d -0.91049532 2.28507125
## 22 c e -1.10381972 5.22559019
## 23 c d -1.63486731 2.83555927
## 24 c e -1.61638249 -2.14570951
## 25 c d -0.83673701 2.98528346
## 26 c e 1.09299912 1.95904174
## 27 c d 1.23509818 0.40683889
##
## [[2]]
## group factor x y
## 1 a d 0.8158402 3.3301319
## 2 a e -0.9997716 -0.2434211
## 3 a d 0.5492103 3.4964264
## 4 a e 0.2797712 3.8808031
## 5 a d 0.9166359 2.5239869
## 6 a e -1.7312573 2.1187425
## 7 a d -1.4795811 4.1985276
## 8 a e 2.2298110 0.8030845
## 9 a d 0.3864989 -1.8991076
## 10 b e 0.6602657 0.4846774
## 11 b d -0.2762352 -3.0661427
## 12 b e 0.2759330 2.1739283
## 13 b d -2.2742312 1.3211731
## 14 b e 0.9080857 1.2263057
## 15 b d -1.0862531 2.1433812
## 16 b e -0.2155267 -0.9310593
## 17 b d -0.7334274 1.6360023
## 18 b e 0.2121178 0.6529848
## 19 c d -0.9391419 -0.8252224
## 20 c e -0.6191936 -2.6937895
## 21 c d 0.2440112 2.3390360
## 22 c e 0.3717434 0.7824270
## 23 c d 0.6272082 4.1331507
## 24 c e -1.0731139 -0.6896905
## 25 c d -0.7086927 3.1952986
## 26 c e 0.9071317 1.6017607
## 27 c d -0.3197056 -0.5539325
##
## [[3]]
## group factor x y
## 1 a d -0.03843418 -0.8932255
## 2 a e 1.10948957 -1.2679198
## 3 a d 0.53632527 -0.7667670
## 4 a e -0.36334846 2.0328268
## 5 a d -0.10550071 0.3240892
## 6 a e 0.33387464 0.9550963
## 7 a d 0.81023105 0.7958981
## 8 a e -1.68369538 1.6008172
## 9 a d 0.66572784 2.6132408
## 10 b e -0.79238753 0.9255882
## 11 b d 1.52772330 -1.9129520
## 12 b e -1.48669240 -0.2477813
## 13 b d -0.67114858 0.6608035
## 14 b e 1.67517745 3.5522463
## 15 b d 0.61193206 0.4881710
## 16 b e -0.23220565 0.6692635
## 17 b d 0.60529332 0.1453578
## 18 b e -1.15910612 0.8862545
## 19 c d -1.16442927 -1.8907672
## 20 c e -0.86992495 4.7656140
## 21 c d -0.26110572 1.2337800
## 22 c e -0.49419566 1.8422654
## 23 c d -1.30582273 4.1548088
## 24 c e 2.02341262 0.4972230
## 25 c d -0.75564882 0.8887513
## 26 c e -0.24159462 0.9549363
## 27 c d 1.09715890 5.6619219