资源描述:
《essentials of the r language》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、2EssentialsoftheRLanguageThereisanenormousrangeofthingsthatRcando,andoneofthehardestpartsoflearningRisfindingyourwayaround.Likewise,thereisnoobviousorderinwhichdifferentpeoplewillwanttolearnthedifferentcomponentsoftheRlanguage.Isuggestthatyouquicklyscandownthef
2、ollowingbulletpoints,whichrepresenttheorderinwhichIhavechosentopresenttheintroductorymaterial,andifyouarerelativelyexperiencedinstatisticalcomputing,youmightwanttoskipdirectlytotherelevantsection.Istronglyrecommendthatbeginnersworkthoroughthematerialintheorder
3、presented,becausesuccessivesectionsbuilduponknowledgegainedfromprevioussections.Thischapterisdividedintothefollowingsections:2.1Calculations2.2Logicaloperations2.3Sequences2.4Testingandcoercion2.5Missingvaluesandthingsthatarenotnumbers2.6Vectorsandsubscr
4、ipts2.7Vectorizedfunctions2.8Matricesandarrays2.9Sampling2.10Loopsandrepeats2.11Lists2.12Text,characterstringsandpatternmatching2.13Datesandtimes2.14Environments2.15WritingRfunctions2.16WritingtofilefromRTheRBook,SecondEdition.MichaelJ.Crawley.©2013Jo
5、hnWiley&Sons,Ltd.Published2013byJohnWiley&Sons,Ltd.ESSENTIALSOFTHERLANGUAGE13Otheressentialmaterialiselsewhere:beginnerswillwanttomasterdatainput(Chapter3),dataframes(Chapter4)andgraphics(Chapter5).2.1CalculationsThescreenprompt>isaninvitationtoputRtowork.Thec
6、onventioninthisbookisthatmaterialthatyouneedtotypeintothecommandlineafterthescreenpromptisshowninredinCourierNewfont.JustpresstheReturnkeytoseetheanswer.Youcanusethecommandlineasacalculator,likethis:>log(42/7.3)[1]1.749795Eachlinecanhaveatmost8192characters,bu
7、tifyouwanttoseealengthyinstructionoracomplicatedexpressiononthescreen,youcancontinueitononeormorefurtherlinessimplybyendingthelineataplacewherethelineisobviouslyincomplete(e.g.withatrailingcomma,operator,orwithmoreleftparenthesesthanrightparentheses,implyingth
8、atmorerightparentheseswillfollow).Whencontinuationisexpected,thepromptchangesfrom>to+,asfollows:>5+6+3+6+4+2+4+8++3+2+7[1]50Notethatthe+continuationpromptdoesnotcarryoutarithmeticp