R语言常用函数(基本)

Python085

R语言常用函数(基本),第1张

vector:向量 numeric:数值型向量 logical:逻辑型向量 character;字符型向量 list:列表 data.frame:数据框

c:连接为向量或列表 sequence:等差序列 rep:重复

length:求长度 subset:求子集 seq,from:to, NA:缺失值 NULL:空对象 sort,order,unique,rev:排序 unlist:展平列表 attr,attributes:对象属性

mode,typeof:对象存储模式与类型 names:对象的名字属性

character:字符型向量 nchar:字符数 substr:取子串 format,formatC:把对象用格式转换为字符串 paste,strsplit:连接或拆分

charmatch,pmatch:字符串匹配 grep,sub,gsub:模式匹配与替换

complex,Re,Im,Mod,Arg,Conj:复数函数

factor:因子 codes:因子的编码 levels:因子的各水平的名字 nlevels:因子的水平个数 cut:把数值型对象分区间转换为因子

table:交叉频数表 split:按因子分组 aggregate:计算各数据子集的概括统计量 tapply:对“不规则”数组应用函数

+, -, *, /, ^, %%, %/%:四则运算 ceiling,floor,round,signif,trunc,zapsmall:舍入 max,min,pmax,pmin:最大最小值

range:最大值和最小值 sum,prod:向量元素和,积 cumsum,cumprod,cummax,cummin:累加、累乘 sort:排序 approx和approx fun:插值 diff:差分 sign:符号函数

abs,sqrt:绝对值,平方根 log, exp, log10, log2:对数与指数函数 sin,cos,tan,asin,acos,atan,atan2:三角函数

sinh,cosh,tanh,asinh,acosh,atanh:双曲函数

beta,lbeta,gamma,lgamma,digamma,trigamma,tetragamma,pentagamma,choose ,lchoose:与贝塔函数、伽玛函数、组合数有关的特殊函数

fft,mvfft,convolve:富利叶变换及卷积 polyroot:多项式求根 poly:正交多项式 spline,splinefun:样条差值

besselI,besselK,besselJ,besselY,gammaCody:Bessel函数 deriv:简单表达式的符号微分或算法微分

array:建立数组 matrix:生成矩阵 data.matrix:把数据框转换为数值型矩阵 lower.tri:矩阵的下三角部分 mat.or.vec:生成矩阵或向量 t:矩阵转置

cbind:把列合并为矩阵 rbind:把行合并为矩阵 diag:矩阵对角元素向量或生成对角矩阵 aperm:数组转置 nrow, ncol:计算数组的行数和列数 dim:对象的维向量

dimnames:对象的维名 row/colnames:行名或列名 %*%:矩阵乘法 crossprod:矩阵交叉乘积(内积) outer:数组外积 kronecker:数组的Kronecker积

apply:对数组的某些维应用函数 tapply:对“不规则”数组应用函数 sweep:计算数组的概括统计量 aggregate:计算数据子集的概括统计量 scale:矩阵标准化

matplot:对矩阵各列绘图 cor:相关阵或协差阵 Contrast:对照矩阵 row:矩阵的行下标集 col:求列下标集

solve:解线性方程组或求逆 eigen:矩阵的特征值分解 svd:矩阵的奇异值分解 backsolve:解上三角或下三角方程组 chol:Choleski分解

qr:矩阵的QR分解 chol2inv:由Choleski分解求逆

<,>,<=,>=,==,!=:比较运算符 !,&,&&,|,||,xor():逻辑运算符 logical:生成逻辑向量 all,any:逻辑向量都为真或存在真

ifelse():二者择一 match,%in%:查找 unique:找出互不相同的元素 which:找到真值下标集合 duplicated:找到重复元素

optimize,uniroot,polyroot:一维优化与求根

if,else,ifelse,switch:分支 for,while,repeat,break,next:循环 apply,lapply,sapply,tapply,sweep:替代循环的函数。

function:函数定义 source:调用文件 call:函数调用 .C,.Fortran:调用C或者Fortran子程序的动态链接库。 Recall:递归调用

browser,debug,trace,traceback:程序调试 options:指定系统参数 missing:判断虚参是否有对应实参 nargs:参数个数 stop:终止函数执行

on.exit:指定退出时执行 eval,expression:表达式计算 system.time:表达式计算计时 invisible:使变量不显示 menu:选择菜单(字符列表菜单)

其它与函数有关的还有:delay,delete.response,deparse,do.call,dput,environment ,,formals,format.info,interactive,

is.finite,is.function,is.language,is.recursive ,match.arg,match.call,match.fun,model.extract,name,parse,substitute,sys.parent ,warning,machine

cat,print:显示对象 sink:输出转向到指定文件 dump,save,dput,write:输出对象 scan,read.table,load,dget:读入

ls,objects:显示对象列表 rm, remove:删除对象 q,quit:退出系统 .First,.Last:初始运行函数与退出运行函数。

options:系统选项 ?,help,help.start,apropos:帮助功能 data:列出数据集分析

每一种分布有四个函数:d――density(密度函数),p――分布函数,q――分位数函数,r――随机数函数。

比如,正态分布的这四个函数为dnorm,pnorm,qnorm,rnorm。下面我们列出各分布后缀,前面加前缀d、p、q或r就构成函数名:

norm:正态,t:t分布,f:F分布,chisq:卡方(包括非中心) unif:均匀,exp:指数,weibull:威布尔,gamma:伽玛,beta:贝塔

lnorm:对数正态,logis:逻辑分布,cauchy:柯西, binom:二项分布,geom:几何分布,hyper:超几何,nbinom:负二项,pois:泊松 signrank:符号秩,

wilcox:秩和,tukey:学生化极差

sum, mean, var, sd, min, max, range, median, IQR(四分位间距)等为统计量,sort,order,rank与排序有关,其它还有ave,fivenum,mad,quantile,stem等。

R中已实现的有chisq.test,prop.test,t.test。

cor,cov.wt,var:协方差阵及相关阵计算 biplot,biplot.princomp:多元数据biplot图 cancor:典则相关 princomp:主成分分析 hclust:谱系聚类

kmeans:k-均值聚类 cmdscale:经典多维标度 其它有dist,mahalanobis,cov.rob。

ts:时间序列对象 diff:计算差分 time:时间序列的采样时间 window:时间窗

lm,glm,aov:线性模型、广义线性模型、方差

1 元音:

1) [i:] 字母组合:ee ea e ie

three tree green sheep meet beef see seek eat tea meat leave lead teacher team mean speak clean please he she me piece receive ceiling

2) [i] 发音字母 i y e

sit picture it is list six mix fix fit pig big build miss myth many twenty happy dictionary defect decide delicious

3) [æ] 发音字母 a

bag hand and ant happy hat map mad bad black back glad flag shall man

4) [e] 字母组合 ea e a

head bread pleasure elephant electric remember sell shell lesson better bed desk hotel yes many any

5) [ə:] 字母组合ir ur ear ur or

girl shirt skirt thirty thirteen third bird turn burn murder nurse turtle Thursday burger learn earn earth heard term her nerd serve work worm work world

6) [ə] 字母组合 er or ou ar o a e u

teacher leader remember player speaker farmer powder doctor actor mayor author tractor delicious gracious pleasure familiar collar dollar together tomorrow today lesson Washington control polite around account ago elephant manta banana Canada Japan china men listen Saturday

7) [a:] 字母组合 ar a

car farm card arm garden fast class last glass plant aunt calm

8) [ʌ] 发音字母 u o ou oo

up supper lunch fun gun hunt cup bus come mother dose brother love above trouble rough flourish blood flood

9) []字母组合 al or au our ar

small wall talk tall hall ball call walk short more lord horse for forty sport door floor store author caught autumn four mourn court bought warm quarrel quarter

10) [ɔ] 发音字母 o a

hot lost lot fox box mop hop loss collar not want wash

11) [u:] 字母组合 oo o u

food moon room gloom broom doom goose tooth shoe do two true truth blue full

12) [u] 字母组合 oo ou u o

look good foot book should could put full bull pull push women whose

13) [ei] 发音字母 a ay ea ai ey

name cake late gate plane April play say may way great break rain paint plain they grey

14) [ai] 发音字母 i y

bike fine find die nine light night high my try fly eye

15) [au] 字母组合 ou ow

house out flour ground account count sound loud around mouse flower down now cow how town

16) [əu] 发音字母 o ow oa

home cold go no phone host ghost know low below grow blow show flow

boat coat goal

17) [ɔ i] 字母组合oy oi

boy toy joy oil soil voice choice

18) [iə] 字母组合 eer

beer deer ear idea near here fierce

19) [εə] 字母组合ear air

pear bear chair air fair care there where

20) [uə] hour tour poor flower shower

2 容易混淆的元音

[æ]/ [e]

bad/ bed hand/ head man /men land /lend pan/ pen sad /said

[i:]/ [ei]

real/ rail greet /great mean /main read/ raid

[e] /[ai]

bet bite red write said side head hide

[au] []

house /horse loud/ lord south /sauce cloud /clause now /nor count /corn

[au] [ɔ]

found/ fond down/ done gown /gone town/ ton

3辅音

1) [p] pen pear play pig pour pull push

2) [b] book big boot bike bread break

3) [t] tree two ten ton town twenty city

4) [d] door dull desk dose do dog dictionary

5) [k] king kite key look cook book kitchen sky (发音字母k)

card cat cream correct climb come account accept (发音字母c)

fox box oxygen x-ray (发音字母x)

school schedule schema (字母组合ch)

6) [g] girl good goal goat grade long language

7) [m] man make moon morning move come comb

8) [n] pen ten nine fine night noon moon clean

9) [ŋ] uncle bank English think thank junk sing king morning evening

10) [l] long land lend lord fly flag black world cold could goal soul

11) [r] read red right run room write

12) [f] five fly fine flag frog fog roof knife life wife cough laugh rough physic photo phone

13) [v] very evening even every voice vest of

14) [s] six sit student same seat kiss miss case scarf (发音字母s)

license city cease cedar ceiling celebrate (发音字母c)

licence piece juice science lance space ace (字母组合ce)

15) [z] zoo zebra zero zap close nose hose suppose pause those whose

16) [] think thank three thirty tooth mouth

17) [ð] that this those these though

18) [ʃ] sheep shoulder ship shoe she brush wash nation attention station social special sure

19) [Ӡ] pleasure

20) [h] hot hop home house horse how who

21) [w] when what where window wind wood

22) [j] yes year yell you your yolk yellow

23) [ʧ] child chicken china chair lunch ouch catch teach

24) [ʤ] age language cabbage vegetable stage bridge joy enjoy join July June junk

25) [tr] tree country try treat track trunk

26) [dr] dry dream drop drive drink

27) [ts] students boots boats goats nuts

28) [dz] goods woods moods hoods

4容易混淆的辅音

[v]/ [w]

vest /west vet /wet vine /wine very /well

[s] []

sink/ think mass/ math miss/ myth sort /sought

[z] [ð]

close/ cloth breeze /breathe

[n] [ŋ]

thin/ thing sin/ sing ran /rang ban /bang win /wing

5 字母,组合音节发音规律

1)a [ei] [æ] [ə] [] [ɔ]

late private grade bake grape nation station page

active hand bank fan parent family glad flag

accept about above formative machine cinema

fast last glass class past father

wash what watch want

2)e [i:] [e] [i] [ə] 不发音

appreciate extremely secret she me he

letter left message generate pebble

decide pretty previous result restore

problem prosperous student confident

active table late wife store lecture

3)i [ai] [i]

high price library ice cream wife size line

fist pick chicken piano fiancé city unit

4)o [əu] [u:] [ʌ] [ə] [ɔ]

lode host cold note okay old home

lose do who whose prove

love some other mother honey company

today tomorrow together control collect

lost hot mock office soft honest

5)u [ju] [u] [ʌ] [ə]

university refuse unique universe huge

put push pull full bull

but brush bucket duck bubble

support suggest

6)c [k] [s]

country camp camera courage cable

city ceiling celebrate cell cease

7)g [g] [ʤ] [ŋ]

girl grade glass glade bag flag

village vegetable bridge gentleman gym

long song sing morning evening

8) l [l] 读音不同

listen learn language collect English gorilla

world cold soil tall sell cool animal

9) n [n] [ŋ]

moon night noodle number

uncle hungry angry young

10) r [r] [](美语发音)

right read write grade progress

card board door floor form north

11)y [j] [i] [ai]

yellow year yell young yolk

university country pretty happy

dyke dying fly buy by my

12)ar [a:] [ə] []

farm card garden mark

dollar

warm quarrel quarter

13) ea [i:] [e] [ei] [iə]

cease season breathe feature meat please

bread breast breath meadow weather

great break

idea realize

14) ear [ə:] [iə]

learn earth earn heard

hear near clear ear fear

15) er [ə:] [ə] [iə]

deserve serve her person

teacher driver anger singer

serious experience mysterious fierce

16) ere [iə] [εə]

here mere fere sere

there

17) ir [ə:] [ai]

shirt girl skirt

admire desire

18) oo [u:] [u] [ʌ] []

room tool cool moon noon goof food

good foot stood wood wool cook wood book

blood flood

door floor

19) or [] [ə:] [ə]

short form corn born for

work world worm word worst

tractor doctor actor sector senior senator

20) oor [] [uə]

door floor

moor poor boor

21) our [au] []

hour tour flour bourn lour

pour court four mourn

22) ou [au] [ʌ] [ə]

house mouth mouse sound found

enough trouble touch

delicious gracious prosperous

23) ow [əu] [au]

window meadow know show low

now town how down cow

24) se [z] [s]

nose suppose gose lose pose rose

mouse house

25) th [] [ð]

thank think thought cloth

clothes that this then than

26) sion [ʃən] [Ӡən]

propulsion tension progression passion

protrusion provision conclusion television

27) tion [ʃən] [ʧən](不常见)

station nation translation attention

question