我有一个数据框,我想Category
根据PCC
.
> head(newdf)
ItemId Category PCC
1 5063660193 Go to Gifts 2
2 24154563660193 Go to Gifts 1
2.1 24154563660193 All Gifts 1
3 26390063660193 Go to Gifts 3
3.1 26390063660193 All Gifts 3
4 18700100 Go to Gifts 1
我最初虽然使用该包来执行此操作,但不幸的是,R 版本 3.0.2 没有sqldf
依赖项 ( )。tcltk
使用sqldf
类似于以下的调用应该可以完成这项工作:
# ranking by category
rank <- sqldf("select
nf.ItemId,
nf.Category,
nf.PCC,
rank() over(Partition by nf.Category order by nf.PCC, nf.ItemId, nf.Category) as Ranks
from
newdf as nf
order by
nf.Category,
nf.Ranks")
你知道我可以用什么替代品吗?