R语言-关于对象学习的一些注释和实例
2018-01-16 14:26
453 查看
# ------------------------------------------------------------------------------ # object -->> the entity that R is dealing with # object : # atomic-- # numeric--complex--logical--character--raw # object -->> mode-length z <- 0:9 # here, z is an int vector digits <- as.character(z) # here, digits is a chr vector d <- as.integer(digits) # then, d is back to int mode e <- numeric() # empty numeric e[3] <- 17 # change the length and the mode alpha <- c(1:10) alpha <- alpha[2 * 1:5] # obtain the values which address are even length(alpha) <- 3 # save three elements which are at the beginning length(alpha) <- 5 # expand the length of the vector alpha_nia=attributes(alpha) # give the non-intrinsic attributes of the object z <- matrix(1:9,3,3,T) # obtain a matrix # attr(z, "dim") <- c(10,10) # allow R to treat z as a vector that is 10 * 10 # last command is still a stranger for me # in R, every object has a specificated class # which can be numeric, logical, character, list, matrix, array, factor, data.frame winter <- c(1,2,2,3) unclass(winter) # unless() can remove the class mode # --about factors ---->>>> ordered | unordered state <- c( "tas", "sa", "qld", "nsw", "nsw", "nt", "wa", "wa", "qld", "vic", "nsw", "vic", "qld", "qld", "sa", "tas", "sa", "nt", "wa", "vic", "qld", "nsw", "nsw","wa", "sa", "act", "nsw", "vic", "vic", "act") statef <- factor(state) levers(statef) # levels() gives the elements that are diffrent incomes <- c( 60, 49, 40, 61, 64, 60, 59, 54, 62, 69, 70, 42, 56, 61, 61, 61, 58, 51, 48, 65, 49, 49, 41, 48, 52, 56, 59, 46, 58, 43) incmeans <- tapply(incomes, statef, mean) # calculate the average value of each state # below, gives a new function to get the standard error # this is similar to the function handle in matlab # of cause, there is a function, sd(), for the standard reeor calculation stderr <- function(x) sqrt(var(x)/length(x)) incster <- tapply(incomes, statef, stderr) # calculate the standard reeor of each state # about the ordered factors, the levers of the factors are ordered reccording to the 1st letter # ------------------------------------------------------------------------------ # end
----------------------------------------------------------------------------------------------------------------
大家,午安!
相关文章推荐
- 黑马程序员-IOS学习笔记 OC 关于对象方法类方法的一些概念
- 关于LINQ(语言集成查询)的一些学习笔记(没实践过的)
- 处理Clob数据(转)关于oracle中大对象处理的一些方法和实例
- ASP.NET中一些关于http对象的学习
- 关于对象实例的一些新手问题
- 关于oracle中大对象处理的一些方法和实例
- ASP.NET中一些关于http对象的学习(一)
- 关于学习Scala语言的一些感悟
- 关于LINQ(语言集成查询)的一些学习笔记
- 关于oracle中大对象处理的一些方法和实例
- 关于RegExp对象实例的lastIndex属性的一些整理
- java语言基础关于private修饰构造函数,实例对象详解-作者:逝秋
- 学习xhtml的第三课(关于开发工具,添加模板,注释写法,一些注意点)
- 未将对象引用设置到对象的实例都是一些什么错啊
- Java中关于对象串行化的一些讨论
- 关于RDLC报表的一些总结,希望对正在学习使用它的朋友有所帮助
- 关于学习语言的困惑!
- 关于学习操作系统编程的一些建议
- 一些关于学习早晚的哲言
- 关于语言学习的一点感想