随笔分类 -  R

摘要:aggregate(x = xdata$species, by = list(xdata$id), FUN = paste, collapse = ",")aggregate(data = xdata, species ~ id, FUN = paste, collapse = ",") 阅读全文
posted @ 2017-10-09 21:52 Emily_zhu
摘要:来源:http://bbs.pinggu.org/thread-1219536-1-1.html ################ 生成数据 bh=1:100jxh=rep(1:17,c(4,5,6,7,8,4,5,6,7,8,4,5,5,5,6,7,8))relation=c(0,5,6,10,0 阅读全文
posted @ 2017-09-25 17:12 Emily_zhu 阅读(432) 评论(0) 推荐(0)
摘要:R语言中因子(factor)转换成数值型(numeric)的问题 对于数字型的分类型变量,需要保持其值不变且变量类型要强制转换成字符型时,用as.character, 不用as.factor。因为上面链接的问题。 阅读全文
posted @ 2017-07-27 20:13 Emily_zhu 阅读(5295) 评论(0) 推荐(0)
摘要:Numbering rows within groups in a data frame 阅读全文
posted @ 2017-07-12 17:24 Emily_zhu 阅读(1532) 评论(0) 推荐(0)
摘要:The general form of data.table syntax is: .SD , .SDcols , .N 等 .SD stands for something like "Subset of Data.table". There's no significance to the in 阅读全文
posted @ 2017-03-06 17:34 Emily_zhu 阅读(266) 评论(0) 推荐(0)
摘要:data: have <- data.frame(ID=paste0("id", c(101, 102, 102, 103, 103, 104, 105, 105)), info1=c("one", "twoA", "twoB", "threeA", "threeB", "four", "five" 阅读全文
posted @ 2017-03-06 12:16 Emily_zhu 阅读(1423) 评论(0) 推荐(0)
摘要:单变量重命名 b = rename(b,c(target="flag")) 1. library(reshape) 2. c(oldname="newname", oldname2="newname2") 单变量删除 b = b[,names(b)!='age'] 或者 b[,"age"] = NU 阅读全文
posted @ 2016-12-01 15:36 Emily_zhu 阅读(749) 评论(0) 推荐(0)
摘要:1:输入函数名。 2:methods( ),例如methods(quantile)。 3:针对方法2得到的带*的,例stats:::quantile.default。 阅读全文
posted @ 2016-12-01 15:33 Emily_zhu 阅读(1117) 评论(0) 推荐(0)
摘要:next跳出本次循环 break跳出本层循环(当有多个for 循环时,即跳出最近的一个for循环) 阅读全文
posted @ 2016-12-01 15:26 Emily_zhu 阅读(1873) 评论(0) 推荐(0)
摘要:> x<-c(97,93,85,74,32,100,99,67) > sort(x) [1] 32 67 74 85 93 97 99 100 > order(x) [1] 5 8 4 3 2 1 7 6 > rank(x) [1] 6 5 4 3 1 8 7 2 阅读全文
posted @ 2016-11-28 09:50 Emily_zhu 阅读(387) 评论(0) 推荐(0)
摘要:R里面应该用/,而不是\ ,或者用两个\\ R区分大小写,所以应该用C:,而不是c: 阅读全文
posted @ 2016-11-28 09:49 Emily_zhu 阅读(836) 评论(0) 推荐(0)
摘要:以下说明仅针对运用R读取文件的情况 Attention: .csv格式的文件本身已经没有自定义的变量类型。 读取含多位数的数据 1(首选). install.packages("readxl")library(readxl) x<-read_excel("C:\\Users\\Desktop\\da 阅读全文
posted @ 2016-11-25 18:24 Emily_zhu 阅读(263) 评论(0) 推荐(0)