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. Ofcourse this needs to be done for all the individual chargepoint_skeys. So a kind of summarize. How can I get this done?
My code so far to get the dataframe (see image):
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:
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))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.