timestamp()
##------ Sun Apr 05 20:54:06 2015 ------##
该函数可以输入当前的系统时间,可用于耗时很长的程序定时输出当前时间,用于判断程序是否正常运行;也可用于调试,判断哪一段代码效率较低。
a=c(1,2,3,4,5,2,1,2,4,2,5,6)
b=c("A","A","B","B","C","C","C","C","D","D","D","D")
c=c(1,2,3,4,5,5,2,1,2,4,2,5,6,5,6)
d=c("A","A","A","A","B","B","B","C","C","C","C","C","D","D","D")
boxplot(a~b,boxwex=.24,at=1:4-.2,col="orange",axes=FALSE)
# 定义箱式图的宽度
box();axis(2)
axis(1,at=c(1:4-.2,1:4+.2),rep(c("\u2640","\u2642"),each=4))
boxplot(c~d,boxwex=.24,at=1:4+.2,col="yellow",add=TRUE,axes=FALSE)# add
require(maps)
map(database = "state", fill =FALSE, boundary = TRUE, interior = FALSE, col = "grey60", lwd = 0.6,lty = 1, add = FALSE, resolution = 0)
map(database = "state", fill =FALSE, boundary = FALSE, interior = TRUE, col = "grey70", lwd = 0.5,lty = "31", add = TRUE, resolution = 0)
par(cex.axis = 0.7)
map.axes()
x1 = c(-109, -108, -103, -99, -97, -99,-107)
y1 = c(39, 43, 48, 43, 39, 33, 37)
xspline(x = x1, y = y1, shape = 0.9, open =FALSE, border = NA, col = "#00FF0037")
x2 = c(-107, -107, -103, -101, -99, -101,-105)
y2 = c(39, 41, 43, 41, 39, 37, 38)
xspline(x = x2, y = y2, shape = 0.9, open =FALSE, border = NA, col = "#FF000073")
points(-103, 39, pch = 19)
require(fields)
data(ozone2)
x<-ozone2$lon.lat
y<- ozone2$y[16,] # June 18, 1987
fit<- Tps(x,y)
surface(fit)
US(add=TRUE, col="magenta",lwd=2)
title("Daily max 8 hour ozone inPPB, June 18th, 1987")
绘制双重坐标轴的图形不是一个好的图形,会给读者带来很大的迷惑。
plot(1, main = ‘如何折磨读者的眼睛‘)
axis(2, runif(7, .6, 1.4), line=1)
axis(4, runif(3, .6, 1.4), line=1)
x=seq(-5,5,0.1)
plot(x,dnorm(x),type="l") #密度函数曲线
plot(x,pnorm(x),type="l") #分布函数曲线
z是matrix!(不是函数)你要理解三维图形和二维图形是不一样的,并不是说有三个向量x、y、z就能画出3D图来的(除非是只画点),3D图形通常都是一个曲面,因此需要一个grid形式的数据,也就是每一对(x, y)对应的z值。如:
persp(x=1:10, y=1:10,z=matrix(rnorm(10*10),10,10))
df1 == df2
这样比较可以判断数据框中每一对应元素是不是相等。
if(!exists("dataPath")){
dataPath<-choose.dir(default ="", caption = "Please select a data source folder")
}
x=c(1,1,2,2,1,1,2)
y=c(1,2,2,5,5,3,3)
lbls <- c(
"list(x1,y1^(1))","list(x2,y2^(2))","list(x3,y3^(3))",
"list(x4,y4^(4))","list(x5,y5^(5))","list(x6,y6^(6))",
"list(x7,y7^(7))"
)
lbls <- paste("(",lbls,")", "")
{plot(x,y,main="X vsY",xlab="X", ylab="Y",xlim=c(.9,2.1),ylim=c(.9,5))
lines(x,y,col="black",lty="dotted")
text(x,y-.1,labels=parse(text=lbls))}
x=rnorm(1000) # x是你希望对什么数据作核密度估计,density()中n的默认值为512
n=1000 # n是你希望对多少个点作核密度估计,x不太长时可指定n=length(x)
a=density(x,n) # a是density()给出的全部计算结果
a[1:2] # 你想要的密度估计曲线上所有点的坐标,其中
a$y # density()给出的核密度估计值,即图中的纵坐标
a$x # 与a$y对应的横坐标
density.default # density()函数代码
有些函数的源代码是隐藏状态,可以尝试用下列方法获取:
getAnywhere(princomp.default)
library(plotrix)
t<-seq(-pi,pi,0.1)
r<-1-cos(t/2)
radial.plot(r,t,rp.type="p",lwd=3,line.col=2)
for(i in 1:6) { #-- Create objects ‘r.1‘, ‘r.2‘, ... ‘r.6‘ --
nam <- paste("r", i, sep = ".")
assign(nam, 1:i)
}
ls(pattern = "^r..$")
##-- Global assignment within a function:
myf <- function(x) {
innerf <- function(x) assign("Global.res", x^2, envir =.GlobalEnv)
innerf(x+1)
}
myf(3)
Global.res # 16
a <- 1:4
assign("a[1]", 2)
a[1] == 2 # FALSE
get("a[1]") == 2 # TRUE
可转化为复数的运算
(-1+0i)^(1/3)
[1] 0.5+0.8660254i
以下是不同数据类型的“空集”
list()
c()
data.frame()
factor()
原文地址:http://blog.csdn.net/liu7788414/article/details/44891279