配色: 字号:
base-r
2018-10-15 | 阅:  转:  |  分享 
  
???
Alsoseethestringrpackage.
Types
MatricesStrings
m<-matrix(x,nrow=3,ncol=3)
paste(x,y,sep='''')
Joinmultiplevectorstogether.
ConvertingbetweencommondatatypesinR.Canalwaysgo
Createamatrixfromx.
fromahighervalueinthetabletoalowervalue.
paste(x,collapse='''')
Joinelementsofavectortogether.
t(m)
m[2,]-Selectarow
grep(pattern,x)
Findregularexpressionmatchesinx.
Transpose
as.logicalTRUE,FALSE,TRUEBooleanvalues(TRUEorFALSE).
ww
gsub(pattern,replace,x)
Replacematchesinxwithastring.
m%%n
ww
m[,1]-Selectacolumn
ww
Integersor?oatingpointMatrixMultiplication
toupper(x)
Converttouppercase.
as.numeric1,0,1
numbers.
ww
solve(m,n)
tolower(x)
wwConverttolowercase.
m[2,3]-Selectanelement
ww
Findxin:mx=n
Characterstrings.Generally
as.character''1'',''0'',''1''
nchar(x)
preferredtofactors.Numberofcharactersinastring.
ww
ww
Characterstringswithpreset
''1'',''0'',''1'',
ww
as.factor
levels.NeededforsomeLists
levels:''1'',''0''Factors
statisticalmodels.
l<-list(x=1:5,y=c(''a'',''b''))
factor(x)
cut(x,breaks=4)
Alistisacollectionofelementswhichcanbeofdierenttypes.
Turnavectorintoafactor.Can
Turnanumericvectorintoa
MathsFunctions
setthelevelsofthefactorand
factorby‘cutting’into
l[[2]]l[1]l$xl[''y'']
theorder.
log(x)sum(x)sections.
Naturallog.Sum.
NewlistwithNewlistwith
SecondelementElementnamed
exp(x)mean(x)
Exponential.Mean.
onlythefirstonlyelement
ofl.x.
Statistics
max(x)median(x)element.namedy.
Largestelement.Median.
min(x)quantile(x)
Smallestelement.Percentage
lm(y~x,data=df)
prop.test
t.test(x,y)
quantiles.Alsoseethe
Linearmodel.
Testfora
DataFrames
Performat-testfor
dplyrpackage.
round(x,n)rank(x)
RoundtondecimalRankofelements.
dierence
dierencebetween
places.glm(y~x,data=df)
between
means.
df<-data.frame(x=1:3,y=c(''a'',''b'',''c''))
Generalisedlinearmodel.
proportions.
signif(x,n)var(x)Aspecialcaseofalistwhereallelementsarethesamelength.
RoundtonThevariance.
significantfigures.pairwise.t.test
Listsubsettingsummary
aov
Performat-testfor
cor(x,y)sd(x)
Correlation.ThestandardGetmoredetailedinformation
Analysisof
xy
paireddata.
deviation.
outamodel.
variance.
df[[2]]
df$x
1a
VariableAssignment
Distributions
2b
Understandingadataframe
RandomDensityCumulative
>a<-''apple''
Quantile
VariatesFunctionDistribution
Seethefulldata
>a
View(df)
3c
frame.
rnormdnormpnormqnorm
[1]''apple''
Normal
Seethefirst6
rpoisdpoisppoisqpois
Matrixsubsettinghead(df)
Poisson
rows.
TheEnvironment
rbinomdbinompbinomqbinom
Binomial
df[,2]
nrow(df)
runifdunifpunifqunif
ls()Listallvariablesinthe
cbind-Bindcolumns.Uniform
Numberofrows.
environment.
rm(x)Removexfromthe
ncol(df)
Alsoseetheggplot2package.
Plotting
environment.
Numberof
df[2,]
columns.
rm(list=ls())Removeallvariablesfromthe
rbind-Bindrows.plot(x)
plot(x,y)hist(x)
environment.
ValuesofxinValuesofxHistogramof
dim(df)
order.againsty.x.
Numberof
YoucanusetheenvironmentpanelinRStudioto
columnsand
df[2,2]
browsevariablesinyourenvironment.
rows.
Seethelubridatepackage.
Dates
RStudio?isatrademarkofRStudio,Inc.?CCBYMhairiMcNeill?mhairihmcneill@gmail.com?844-448-1212?rstudio.com
Learnmoreatwebpageorvignette?packageversion?Updated:3/15
献花(0)
+1
(本文系Liuxixiya首藏)