Open rain1024 opened 10 years ago
> A=matrix(1:16,4,4)
> A
[,1] [,2] [,3] [,4]
[1,] 1 5 9 13
[2,] 2 6 10 14
[3,] 3 7 11 15
[4,] 4 8 12 16
> A[2,3]
[1] 10
> A[c(1,3),c(2,4)]
[,1] [,2]
[1,] 5 13
[2,] 7 15
> A[1:3,2:4]
[,1] [,2] [,3]
[1,] 5 9 13
[2,] 6 10 14
[3,] 7 11 15
> A[1:2,]
[,1] [,2] [,3] [,4]
[1,] 1 5 9 13
[2,] 2 6 10 14
> A[,1:2]
[,1] [,2]
[1,] 1 5
[2,] 2 6
[3,] 3 7
[4,] 4 8
Auto=read.table("Auto.data")
fix(Auto)
> Auto=read.csv("Auto.csv",header=T,na.strings ="?")
> fix(Auto)
> dim(Auto)
[1] 397 9
> Auto[1:4,]
# names
# Functions to get or set the names of an object.
> names(Auto)
[1] "mpg" "cylinders" "displacement" "horsepower" "weight"
[6] "acceleration" "year" "origin" "name"
> x=rnorm(100)
> y=rnorm(100)
> plot(x,y)
> plot(x,y,xlab="this is the x-axis",ylab="this is the y-axis",
main="Plot of X vs Y")
> pdf("Figure.pdf")
> plot(x,y,col="green")
> dev.off()
null device
1
# The contour() function produces a *contour plot* in order to represent
# three-dimensional data;
# it is like a topographical map. It takes three arguments:
# 1. A vector of thexvalues (the first dimension),
# 2. A vector of theyvalues (the second dimension), and
# 3. A matrix whose elements correspond to thezvalue (the third dimension)
# for each pair of (x,y) coordinates.
> x=seq(1,10)
>x
[1]12345678910
> x=1:10
>x
[1]12345678910
> x=seq(-pi,pi,length =50)
>y=x
> f=outer(x,y,function (x,y)cos(y)/(1+x^2))
> contour(x,y,f)
> contour(x,y,f,nlevels =45,add=T)
> fa=(f-t(f))/2
> contour(x,y,fa,nlevels =15)
> image(x,y,fa)
> persp(x,y,fa)
> persp(x,y,fa,theta=30)
> persp(x,y,fa,theta=30,phi=20)
> persp(x,y,fa,theta=30,phi=70)
> persp(x,y,fa,theta=30,phi=40)
install.packages("ggplot2")
Ubuntu
apt-get install r-base
References
Vector, matrix
1. Basic
2. Produce data