楼主: pang20120
4440 25

[其他] R学习笔记 [推广有奖]

11
pang20120 发表于 2015-5-16 19:12:09
日期值
Sys.Date()可以返回当天的日期
date()则返回当前的日期和时间  format ()l来输出指定格式的日期值
today<-Sys.Date()
format(today,format="%B %d %Y)
format(today,format="%A")
as.Date()用于使日期以数值形式存储日期变量

12
pang20120 发表于 2015-5-18 09:18:03
转换数据类型:
a<-c(1,2,3)
is.numeric(a)
is.vector(a)
a<-as.character(a)
is.numeric(a)
is.character(a)

13
pang20120 发表于 2015-5-18 10:57:30
读取xls文件
install.packages(RODBC)
library(RODBC)
x<-odbcConnectExcel("tourism.xls")
data<-sqlFetch(x,"Sheet4")

14
pang20120 发表于 2015-5-21 10:22:32
数据排序:
#vector
x<-c(3,4,6,2,9)
order(x)
x[order(x)]
x[order(x,decreasing=T)]
order(-x)
#dataframe
x<-c(7,4,5,3,2,8)
y<-c(39,20,34,90,23,11)
order(x,y)#only print x's order,no y's
table1<-data.frame(X=x,Y=y)
table1
order(table1$X,table1$Y)#x asc, y asc,print the row number sequence
table1[order(table1$X,-table1$Y),]# x asc ,y desc
table1[order(-table1$X,table1$Y),]#x desc y asc
table1[order(-table1$X,table1$Y),]# x desc y desc

15
pang20120 发表于 2015-5-21 16:53:48
添加列:
total<-merge(dataframeA,dataframeB,by=c("ID","country"))
添加行:
total<-rbind(dataframeA,dataframeB)
数据集取子集:
进入(保留)变量

16
pang20120 发表于 2015-5-30 21:45:12
高级数据管理:
数学函数:
abs() sqrt ceiling不小于x的整数 floor 不大于x的整数 trunc 向0的方向取x中的整数部分
round 将x舍入为指定的小数 signif 将x舍入为指定的有效数字位数 cos sin tan acos asin atan acosh
asinh atanh log(x) 为自然对数 log10(x)为常用对数 exp
统计函数:
mean  median sd var mad quantile range sum diff(x,lag=n) 滞后差分lag用以指定滞后几项   min max
scale(x)为数据对象进行中心化或标准化

17
pang20120 发表于 2015-5-30 21:58:38
统计函数:
d=密度函数(density)
p=分布函数(distribution function)
q=分位数函数(quantile function)
r=生成随机数
概率分布:
beta beta分布   binom 二项分布   cauchy 柯西分布 exp 指数分布
f  F分布  gamma gamma 分布  geom 几何分布   hyper 超几何分布
lnorm 对数正态分布  logis logistic分布 multinom 多项分布  norm正态分布
pois 泊松分布 signrank  wilcoxon 符号秩分布   t  t分布  unif 均匀分布
weibull weibull分布  wilcoxon  wilcoxon秩和分布

18
pang20120 发表于 2015-5-31 10:44:27
实用函数:
length(x) 对象x的长度
seq(from,to,by)生成一个序列
rep(x,n)将x重复n次
cut(x,n)将连续型变量x分割为有着n个水平的因子
pretty(x,n)创建美观的分割点
cat(...,file="myfile",append=F)连接...中的对象,并将其输出到屏幕上或文件中

19
cuilihui501 在职认证  发表于 2015-5-31 10:48:26
看了你的日记,复习一下,受益匪浅

20
麦琼辉 发表于 2015-6-1 16:27:49
学习&复习

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
jg-xs1
拉您进交流群
GMT+8, 2025-12-21 19:50