ImageVerifierCode 换一换
格式:PDF , 页数:26 ,大小:122.22KB ,
资源ID:1753662      下载积分:10 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.docduoduo.com/d-1753662.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(r - variables, data frames etc.pdf)为本站会员(weiwoduzun)主动上传,道客多多仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知道客多多(发送邮件至docduoduo@163.com或直接QQ联系客服),我们立即给予删除!

r - variables, data frames etc.pdf

1、RVariables, data frames etc.R.M. RipleyDepartment of StatisticsUniversity of Oxford2008/9R.M. Ripley (University of Oxford) R 2008/9 1 / 19Using R as a calculatorComputer representation of numbersReal numbers are not stored exactly on computers. Use binaryversion of “scientific” notation e.g. 1:234

2、102This needs care e.g.x, =, =! (not), | (or), | (or), & (and) & (and)Note difference between |,& and |,&: former work on vectors,latter only consider one element.Exampleif x=(TRUE,FALSE,TRUE) and y=(FALSE,TRUE,TRUE) thenx|y=(TRUE,TRUE,TRUE), x|y=(TRUE),x&y=(FALSE,FALSE,TRUE), x&y=(FALSE)R.M. Ripley

3、 (University of Oxford) R 2008/9 13 / 19Manipulating variablesDates and TimesIf treated as character, easy to read, but not easy to manipulateTreated as special types, several different optionsSimple: as.Date() does not deal with timesPackage chron for dates and times but not time zonesPOSIXct and P

4、OSIXlt for times zones.All stored internally as numerics, but in different ways. Cansubtract two dates. Result is an object with class timediff.R.M. Ripley (University of Oxford) R 2008/9 14 / 19Manipulating variablesDates and Times: Examplesthe function as.Date() takes as arguments a character vari

5、ableand a format stringmyDate-as.Date(10-Jan-1993,format=%d-%b-%Y)class(myDate) is “Date“,as.numeric(myDate) is 8410, the number of days since 1stJanuary 1970.R.M. Ripley (University of Oxford) R 2008/9 15 / 19Manipulating variablesSome useful Functionsc,:,seq,repc(1,a) combines its arguments to for

6、m a vector. If any arecharacter (as here), the vector will be of characters.The colon (:) is useful for generating sequences:1:5 is the same as c(1,2,3,4,5)seq(1,10,by=2) gives (1,3,5,7,9)rep is also useful for creating vectors:rep(c(1,2),times=3) gives (1,2,1,2,1,2)rep(c(1,2),each=3) gives (1,1,1,2

7、,2,2)R.M. Ripley (University of Oxford) R 2008/9 16 / 19Manipulating variablesMore functionspastepaste adds together character vectors:paste(c(1,2),c(x,y,z) is a character vector oflength 31 “1 x“ “2 y“ “1 z“Notice the recycling of the first argument.The pieces of the result can be joined together u

8、sing theargument collapse:paste(c(1,2),c(x,y,z),collapse= ) is acharacter vector of length 1,“1 x 2 y 1 z“R.M. Ripley (University of Oxford) R 2008/9 17 / 19Manipulating variablesYet more functionssort,tablesort(x) sorts the vector x into increasing ordersort(x,decreasing=TRUE) sorts the vector x in

9、to decreasingordertable(x) creates a table showing the count of elements equal toeach value. Most useful where x is a vector of factors or integerse.g. table(rpois(20,5) gives2 3 4 5 6 7 83 2 2 6 3 3 1R.M. Ripley (University of Oxford) R 2008/9 18 / 19ExercisesExercises 2Create a list of all the dat

10、es in 2007, using seq and as.Date.There is a version of cut for dates, called cut.Date. Use this tocreate a factor corresponding to the week of the year in which thedates fall. Start the weeks on Sundays.Create a vector of length 100, with integer values in the range1 : 5, randomly ordered. (Hint: l

11、ook at the function sample.)Use paste to create a vector of labels: (Colour 1,Colour2,Colour 3,Colour 4,Colour 5)Use the factor command to create a factor from this vector, withthe labels created above.Create a data frame with 100 rows and two columns, one arandom sample of dates in 2007, and one the factor createdabove.R.M. Ripley (University of Oxford) R 2008/9 19 / 19

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报