-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdemo.R
More file actions
75 lines (52 loc) · 1.25 KB
/
demo.R
File metadata and controls
75 lines (52 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# TODO: Add comment
#
# Author: EASON
###############################################################################
prime<-function(n)
{
prime1<-function(x)
{
y<-TRUE
for(i in (x%/%2):2)
{
if(x%%i==0) y=FALSE
if(x==2 | x==3) y=TRUE
}
y
}
x<-c()
for (i in 2:n)
{
if(prime1(i)) x<-c(x,i)
if(i==n) return(x)
}
}
prime(100)
prime(1000)
mean(abs(rnorm(100)))
mean(rnorm(100))
rnorm(100)
x <- data.frame(matrix (1:30,nrow = 5 , byrow = T) )
dim( x )
print ( x )
new.x1 <- x[-c ( 1, 4 ) , ] #row
new.x2 <- x[,-c(2,3)] # col
new.x1;new.x2
x <- array ( 1:24 , 2:4 )
x
year <- 1995:2005
x1 <- data.frame ( year , GDP = sort ( rnorm( 11 , 1000 , 100 ) ) )
x2 <- data.frame ( year , UR = rnorm( 11 , 5 , 1 ) )
par (mar = c ( 5 , 4 , 4 , 6 )+0.1 )
plot ( x1 , axes = FALSE, type="l")
axis ( 1 , at = year , label = year ) ; axis( 2 )
par (new = T, mar = c ( 10 , 4 , 10 , 6 ) + 0.1 )
plot ( x2 , axes = FALSE, xlab = "" , ylab = "" , col = "red" , type= "b")
mtext ("UR(%)" , 4 , 3 , col="red")
axis ( 4 , col ="red" , col . axis = "red")
x<-c(0.10, 0.11, 0.12, 0.13, 0.14, 0.15,
0.16, 0.17, 0.18, 0.20, 0.21, 0.23)
y<-c(42.0, 43.5, 45.0, 45.5, 45.0, 47.5,
49.0, 53.0, 50.0, 55.0, 55.0, 60.0)
lm.sol<-lm(y ~ 1+x)
summary(lm.sol)