从删除因子标签停止收集功能 [英] Stop gather function from dropping factor labels

查看:15
本文介绍了从删除因子标签停止收集功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 tidyr 中使用 Gather 函数 - 但它正在从分解数据中去除标签.我的数据看起来像这样:

I'm trying to use the gather function in tidyr - but it is stripping out the labels from factored data. My data looks something like this:

> require(tidyr)
> messy = data.frame(x=rep(seq(0,2),2),y=runif(6),z=runif(6),source=c('good','bad'))
> messy
  x          y         z source
1 0 0.37627685 0.9108316   good
2 1 0.77593147 0.9944256    bad
3 2 0.01105364 0.1183923   good
4 0 0.37755463 0.6761343    bad
5 1 0.86333114 0.7312482   good
6 2 0.69085345 0.8288506    bad

>tidy = gather(messy,coordinate,value,y:z)
>tidy
   x source coordinate      value
1  0      2          y 0.37627685
2  1      1          y 0.77593147
3  2      2          y 0.01105364
4  0      1          y 0.37755463
5  1      2          y 0.86333114
6  2      1          y 0.69085345
7  0      2          z 0.91083162
8  1      1          z 0.99442560
9  2      2          z 0.11839230
10 0      1          z 0.67613427
11 1      2          z 0.73124818
12 2      1          z 0.82885055

Tidy 已经按照宣传的那样收集了 yz 变量,但是 source 变量现在是一个整数.

Tidy has gathered the y and z variables as advertised, but the source variable is now an integer.

我做错了什么?

推荐答案

这是这里报告的错误:https://github.com/hadley/tidyr/issues/104

似乎它已在 tidyr 0.3.1 中修复

It seems like it was fixed in tidyr 0.3.1

这篇关于从删除因子标签停止收集功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆