RNote__Reshape2
2015-06-26 20:01
260 查看
melt
parse_formula
cast
recast
colsplit
分解到重组:melt——cast
为泛型函数,具体有:
melt.data.frame for data.frames
melt.array for arrays, matrices and tables
melt.list for lists
id.vars是分类关键词,measure.vars是在数据data中只选择部分变量(列)输出。
formula:a~b~c,其中c是最外围维度,b表示列,a表示行。
parse_formula
cast
recast
colsplit
分解到重组:melt——cast
melt
融化数据,变为长格式;为泛型函数,具体有:
melt.data.frame for data.frames
melt.array for arrays, matrices and tables
melt.list for lists
## S3 method for class ' data.frame ' melt(data, id.vars, measure.vars, variable.name = "variable", ..., na.rm = FALSE, value.name = "value", factorsAsStrings = TRUE)
id.vars是分类关键词,measure.vars是在数据data中只选择部分变量(列)输出。
parse_formula
将字符串转化为cast中的可执行formula。reshape2:::parse_formula("a + ...", letters[1:6]) reshape2:::parse_formula("a ~ b + d")
cast
浇铸,重组数据。dcast(data, formula, fun.aggregate = NULL, ..., margins = NULL, subset = NULL, fill = NULL, drop = TRUE, value.var = guess_value(data)) acast(data, formula, fun.aggregate = NULL, ..., margins = NULL, subset = NULL, fill = NULL, drop = TRUE, value.var = guess_value(data))
> recast(french_fries, time ~ variable, id.var = 1:4) Aggregation function missing: defaulting to length(72代表长度) time potato buttery grassy rancid painty 1 1 72 72 72 72 72 2 2 72 72 72 72 72 3 3 72 72 72 72 72 4 4 72 72 72 72 72 5 5 72 72 72 72 72 6 6 72 72 72 72 72 7 7 72 72 72 72 72 8 8 72 72 72 72 72 9 9 60 60 60 60 60 10 10 60 60 60 60 60
formula:a~b~c,其中c是最外围维度,b表示列,a表示行。
recast
将melt与cast一步完成;recast(data, formula, ..., id.var, measure.var)
colsplit
> x <- c("a_1", "a_2", "b_2", "c_3") > vars <- colsplit(x, "_", c("trt", "time")) > vars trt time 1 a 1 2 a 2 3 b 2 4 c 3 > str(vars) 'data.frame': 4 obs. of 2 variables: $ trt : chr "a" "a" "b" "c" $ time: int 1 2 2 3
相关文章推荐
- SQLSERVERS 数据整理方法
- 向大家推荐一个收集整理正则表达式的网站
- 处理Plot rendering error
- R语言书籍的学习路线图
- 20120919_01
- 20120919_02
- 20120919_3
- Review JDBC
- Win2003SN
- 解决rJava无法找到jvm.dll的问题
- System Center 2012
- How to configure a RPC Client Access
- R改工作空间
- R语言基础画图
- otrs 备注 客户门户只能显示类型为外部的注释
- R的若干基因及争论
- KVM或Xen遇到Unable to retrieve http images/install.img
- Linux Mint安装最新版R
- R NOTE -- learn intro
- 关于R语言里的调用类型(call)