gpt4 book ai didi

r - 将值列扩展为分类数据

转载 作者:行者123 更新时间:2023-12-02 08:15:16 24 4
gpt4 key购买 nike

<分区>

我有这个data.frameff:

ff<-data.frame(dest = c("NY", "NY", "LA", "LA"), 
st_ti = c("ok", "bad", "ok", "bad"),
qty = c(2,2,2,1))

ff:

 dest st_ti qty
1 NY ok 2
2 NY bad 2
3 LA ok 2
4 LA bad 1

我想展开,所以它都是分类数据,如下所示:

gg<-data.frame(dest = c("NY", "NY", "NY", "NY", "LA", "LA","LA"), 
st_ti = c("ok", "ok", "bad", "bad", "ok", "ok", "bad"))

gg:

  dest st_ti
1 NY ok
2 NY ok
3 NY bad
4 NY bad
5 LA ok
6 LA ok
7 LA bad

我想从 tidyr 包中做类似 gather 的事情,但我不相信这个选项在这里可用。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com