资源描述:
《reilly media] r cookbook input and output》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、CHAPTER4InputandOutputIntroductionAllstatisticalworkbeginswithdata,andmostdataisstuckinsidefilesanddatabases.Dealingwithinputisprobablythefirststepofimplementinganysignificantstatisticalproject.Allstatisticalworkendswithreportingnumbersbacktoaclient,evenifyouaretheclient.Formattingandpro
2、ducingoutputisprobablytheclimaxofyourproject.CasualRuserscansolvetheirinputproblemsbyusingbasicfunctionssuchasread.csvtoreadCSVfilesandread.tabletoreadmorecomplicated,tabulardata.Theycanuseprint,cat,andformattoproducesimplereports.Userswithheavy-dutyinput/output(I/O)needsarestronglyencou
3、ragedtoreadtheRDataImport/Exportguide,availableonCRANathttp://cran.r-project.org/doc/manuals/R-data.pdf.Thismanualincludesimportantinformationonreadingdatafromsourcessuchasspreadsheets,binaryfiles,otherstatisticalsystems,andrelationaldatabases.APhilosophicalNoteSeveralofmyStatisticalAnal
4、ysisSystem(SAS)friendsaredisappointedwiththeinputfacilitiesofR.TheypointoutthatSAShasanelaboratesetofcommandsforreadingandparsinginputfilesinmanyformats.Rdoesnot,andthisleadsthemtoconcludethatRisnotreadyforrealwork.Afterall,ifitcan’treadyourdata,whatgoodisit?Ithinktheydonotunderstandthed
5、esignphilosophybehindR,whichisbasedonastatisticalpackagecalledS.TheauthorsofSworkedatBellLabsandweresteepedintheUnixdesignphilosophy.Akeystoneofthatphilosophyistheideaofmodulartools.ProgramsinUnixarenotlarge,monolithicprogramsthattrytodoeverything.Instead,theyaresmaller,specializedtoolst
6、hateachdoonethingwell.TheUnixuserjoinstheprogramstogetherlikebuildingblocks,creatingsystemsfromthecomponents.71Rdoesstatisticsandgraphicswell.Verywell,infact.Itissuperiorinthatwaytomanycommercialpackages.Risnotagreattoolforpreprocessingdatafiles,however.TheauthorsofSassumedyouwouldperfor
7、mthatmungingwithsomeothertool:perl,awk,sed,cut,paste,whateverfloatsyourboat.Whyshouldtheyduplicatethatcapability?Ifyourdataisdifficulttoaccessordifficulttoparse,considerusinganoutboardtooltopreprocessthedatabeforeloadingitintoR.LetRdowhatRdoesbest.4.1EnteringDatafromtheKe