Assigning group ID with ddply

后端 未结 2 1465
走了就别回头了
走了就别回头了 2021-02-01 11:01

Pretty basic performance question from an R newbie. I\'d like to assign a group ID to each row in a data frame by unique combinations of fields. Here\'s my current approach:

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-01 11:21

    Try using the id function (also in plyr):

    df$id <- id(df[c("st.num", "st.name")], drop = TRUE)
    

    Update:

    The id function is considered deprecated since dplyr version 0.5.0. The function group_indices provides the same functionality.

提交回复
热议问题