Subsetting Data - Quick-R

文章推薦指數: 80 %
投票人數:10人

R has powerful indexing features for accessing object elements. These features can be used to select and exclude variables and observations. The following code ... RTutorial RInterface DataInput DataManagement Statistics AdvancedStatistics Graphs AdvancedGraphs 65),] #or attach(mydata) newdata65),] detach(mydata) SelectionusingtheSubsetFunction Thesubset()functionistheeasiestwaytoselectvariablesandobservations.Inthefollowingexample,weselectallrowsthathaveavalueofagegreaterthanorequalto20oragelessthen10.WekeeptheIDandWeightcolumns. #usingsubsetfunction newdata=20|age<10, select=c(ID,Weight)) Inthenextexample,weselectallmenovertheageof25andwekeepvariablesweightthroughincome(weight,incomeandallcolumnsbetweenthem). #usingsubsetfunction(part2) newdata25, select=weight:income) Topracticethesubset()function,trythisthisinteractiveexercise.onsubsettingdata.tables. RandomSamples Usethesample()functiontotakearandomsampleofsizenfromadataset. #takearandomsampleofsize50fromadatasetmydata #samplewithoutreplacement mysample



請為這篇文章評分?