简体   繁体   English

如何从第 4 列 grouped_by 第 1 列中的 id 的第 3 列中获取最大值(范围 1-2)?

[英]How to get the largest value (range 1-2) from column 3 in a 4th column grouped_by the id's in column 1?

I want R to replace all the rows with the same chargepoint_skey and socketsinuse by just one row with that particular chargepoint_skey and socketsinuse.我希望 R 将所有具有相同chargepoint_skey 和 socketsinuse 的行替换为仅具有特定chargepoint_skey 和 socketsinuse 的一行。 Ofcourse this needs to be done for all the individual chargepoint_skeys.当然,这需要对所有单独的 chargepoint_skeys 进行。 So a kind of summarize.所以一种总结。 How can I get this done?我怎样才能完成这项工作?

My code so far to get the dataframe (see image):到目前为止,我获取 dataframe 的代码(见图):

vraag_5 <- FACT_CHARGESSESION_JOINDIMLOCATION %>%
             select(ChargePoint_skey, Socket_ID) %>%
             group_by(ChargePoint_skey) %>%
             mutate(Socket_ID = str_replace_all(Socket_ID, "XXXXXX", "0")) %>%
             mutate(socketsinuse = max(Socket_ID))

Update after changing code:更改代码后更新:

dataframe3数据框3

Try changing your code to:尝试将您的代码更改为:

vraag_5 <- FACT_CHARGESSESION_JOINDIMLOCATION %>%
                mutate(Socket_ID = as.numeric(stringr::str_replace_all(Socket_ID,
                                   "XXXXXX", "0"))) %>%
                group_by(ChargePoint_skey) %>%
                summarise(socketsinuse = max(Socket_ID, na.rm = TRUE))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从定义的列中减去每第4列 - Subtract every 4th column from a defined column 在第4列中分隔两个字母字符串 - Separate two letter string in 4th column 从另一列的 RANGE 调节一列的值的问题 - Problems with conditioning a column's value from another column's RANGE Python / R:如果2列在多行中具有相同的值,请在第3列中添加值,然后对第4、5和6列取平均值 - Python/R : If 2 columns have same value in multiple rows, add the values in the 3rd column and average the 4th, 5th and 6th column 如何从数据框中的分组列中获取 2 的所有组合 - How to get all combinations of 2 from a grouped column in a data frame 根据与第4列匹配的第3列,将一列中的值替换为另一列 - Replacing values in one column with another based on a 3rd column matching a 4th 列中的分组过滤器公共值 - Grouped filter common value in a column 我有一个包含10列和数千行的数据框。 我想用NA替换第4列(值&lt;= 0.05)。 如何使用R脚本执行此操作 - I have a data frame with 10 columns and thousand of rows. I want to replace 4th column (value<=0.05) with NA. How can I do this using R script 从数据框中的列中提取唯一值,按 ID 分组 - Extract unique values from column in dataframe, grouped by ID 随机值如何考虑特定列的最小值和最大值 - How random values considering the smallest and largest value of a specific column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM