subset function - RDocumentation
文章推薦指數: 80 %
Return subsets of vectors, matrices or data frames which meet conditions. ... in recent versions of R this can simply be subset(state.x77, grepl("^M", nm), ... base(version3.6.2)DescriptionReturnsubsetsofvectors,matricesordataframeswhichmeetconditions.Usagesubset(x,…)#S3methodfordefault subset(x,subset,…)#S3methodformatrix subset(x,subset,select,drop=FALSE,…)#S3methodfordata.frame subset(x,subset,select,drop=FALSE,…)Argumentsxobjecttobesubsetted.subsetlogicalexpressionindicatingelementsorrowstokeep: missingvaluesaretakenasfalse.selectexpression,indicatingcolumnstoselectfroma dataframe.droppassedonto[indexingoperator.…furtherargumentstobepassedtoorfromothermethods.ValueAnobjectsimilartoxcontainjusttheselectedelements(for avector),rowsandcolumns(foramatrixordataframe),andsoon.WarningThisisaconveniencefunctionintendedforuseinteractively.For programmingitisbettertousethestandardsubsettingfunctionslike [,andinparticularthenon-standardevaluationof argumentsubsetcanhaveunanticipatedconsequences.DetailsThisisagenericfunction,withmethodssuppliedformatrices,data framesandvectors(includinglists).Packagesanduserscanadd furthermethods. Forordinaryvectors,theresultissimply x[subset&!is.na(subset)]. Fordataframes,thesubsetargumentworksontherows.Note thatsubsetwillbeevaluatedinthedataframe,socolumnscan bereferredto(byname)asvariablesintheexpression(seetheexamples). Theselectargumentexistsonlyforthemethodsfordataframes andmatrices.Itworksbyfirstreplacingcolumnnamesinthe selectionexpressionwiththecorrespondingcolumnnumbersinthedata frameandthenusingtheresultingintegervectortoindexthe columns.Thisallowstheuseofthestandardindexingconventionsso thatforexamplerangesofcolumnscanbespecifiedeasily,orsingle columnscanbedropped(seetheexamples). Thedropargumentispassedontotheindexingmethodfor matricesanddataframes:notethatthedefaultformatricesis differentfromthatforindexing. Factorsmayhaveemptylevelsaftersubsetting;unusedlevelsare notautomaticallyremoved.Seedroplevelsforawayto dropallunusedlevelsfromadataframe.SeeAlso[, transform droplevelsExamples#NOTRUN{ subset(airquality,Temp>80,select=c(Ozone,Temp)) subset(airquality,Day==1,select=-Temp) subset(airquality,select=Ozone:Wind) with(airquality,subset(Ozone,Temp>80)) ##sometimesrequiringalogical'subset'argumentisanuisance nm
延伸文章資訊
- 1R语言subset和merge函数的使用_lijinxiu123的博客 - CSDN
R语言subset和merge函数的使用. ... 2、subset函数,从某一个数据框中选择出符合某条件的数据或是相关的列 (1)单条件查询.
- 2R語言subset和merge函式的使用- IT閱讀
R語言subset和merge函式的使用 · > selectresult=subset(df1,name=="aa",select=c(age,sex)); > · > selectresul...
- 3subset function - RDocumentation
Return subsets of vectors, matrices or data frames which meet conditions. ... in recent versions ...
- 4Subsetting Data | R Learning Modules - IDRE UCLA
1. Subsetting variables ... To manipulate data frames in R we can use the bracket notation to acc...
- 5R語言subset()用法及代碼示例- 純淨天空
R program to create # subset of a data frame # Creating a Data Frame df<-data.frame(row1 = 0:2, r...