我需要计算R中的
Dense Rank,就像我们在Spotfire中使用的那样。我尝试了rank()函数在R中,但这不起作用。为此,您可以考虑下面的数据框架,其中有5列,如City, Region, Market, Year, Number_measure
您可以考虑下表进行计算。
城市<- c("Nagpur“、”孟买“、"Pune”、"Aurangabad“、"Aurangabad”、"Solapur“、"Nashik”、"Aurangabad“、"Auric”、"Latur“、”孟买“、"Pune”、“Aurangabad”、"Auric“、”Aurangabad“、"Auric”、“Aurangabad”、“孟买”、"Pune“、"Auric”、“孟买”、"Pune“、"Pune”、"Aurangabad“、"Auric”、"Solapur“、”Nashik“区域<- c(”Vid港“、”孟买地区“、”西Maharashtra“、"Marathwada”、"Marathwada“、"West Maharashtra”、"North Maharashtra“、"Marathwada”、“孟买地区”、"West Maharashtra“、"Marathwada“、"Marathwada”、“孟买地区”、"West Maharashtra“、”Vid港“、”孟买地区“、"West Maharashtra”、“Vid港”、“孟买地区”、"West Maharashtra“、"Marathwada”、"West Maharashtra",“北马哈拉施特拉邦”市场<- c(“公众”、“非公众”、“公众”、“公众<- c年( 2021、2022、2022、2023、2022、2022、2022、2022、2022、2022、2022、2022、2024、2023、2025、2026、2021、2022、2022、2022、2022、2022年、2022年、2022、2022、2022、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2021年、2022年、2022年、2022年、2022年、2021年、2022年、2022年、2022年、2021年、2022年、2022年、2021年、2022年、2022年、2022年、2021年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2022年、2030299576、49090894、53157520、49631953、43065620、39234446、38298719、4143774、14631379、31659688、50734152、55101038、51630622、45200506、41854513、41215679、4566837、14384281、27952862、44175298、50610826、50342076、46282737、44193037、44064169、7849937) MainData <- data.frame(城市、地区、市场、年份Number_Measure)城市地区市场年Number_Measure那格普尔维德堡公共2021年孟买地区非公共2022年48028137浦那西马哈拉施特拉邦公共2022 3912303奥兰加巴德马拉特瓦达非公共2023 13654456金城马拉斯瓦达公共2020 30299576索拉普尔西马哈拉施特拉邦非公共2021 49090894Nashik North Maharashtra公共2021 53157520 Aurangabad Marathwada非公共2022 49631953 Aurangabad Marathwada公共2022 43065620 Latur Marathwada非公共2022 39234446孟买地区2022 38298719 Pune West Maharashtra非公共2024 4143774 Aurangabad Marathwada公共2023 14631379金市Marathwada非公共2025年31659688金城马拉特瓦达公共2026 50734152金市马拉特瓦达非公共2021 55101038孟买地区公共2022 51630622浦那西马哈拉施特拉邦公共2022 45200506纳格普尔维德港2023 4185454513孟买地区非公共2020年41215679浦那西马哈拉施特拉邦公共2021 4566837纳格普尔14384281孟买地区公共2022 27952862浦那西马哈拉施特拉邦非公共2022 44175298奥兰加巴德马拉特瓦达公共2022 50610826金城马拉斯瓦达非公共2022 50342076奥兰加巴德马拉斯瓦达公共2024 46282737金城马拉特瓦达非公共2023 44193037索拉普尔西马哈拉施特拉邦2025年44064169纳希克北马哈拉施特拉邦公共2026 7849937
现在我需要在Rank的基础上找到Number_Measure,Key应该是City, Regions, Market, Year
在中,为这个Dense Rank函数提供了参考- https://docs.tibco.com/pub/spotfire/7.0.1/doc/html/ncfe/ncfe_ranking_functions.htm。
发布于 2022-02-18 08:43:54
请尝试
dense_rank包中的dplyr函数
MainData$MeasureRank <- dense_rank(MainData$Number_Measure)
https://stackoverflow.com/questions/71161006
复制相似问题