Quantcast
Viewing all articles
Browse latest Browse all 2

Answer by akrun for Convert multiple entries to a single row with a vector column in R

It may be better to keep it in a list instead of a single string after doing the grouping by 'Name'

library(dplyr)old_way %>%   group_by(Name) %>%  summarise(Last_Day = last(Day),             Avg_Purchase = mean(Purchase),             Day = list(Day), Purchase = list(Purchase), .groups = 'drop')

-output

# A tibble: 3 x 5#  Name   Last_Day Avg_Purchase Day       Purchase #  <chr>     <int>        <dbl> <list>    <list>   #1 Dora          7         24.5 <int [4]> <int [4]>#2 Gerald       10         28   <int [3]> <int [3]>#3 John          3         21   <int [3]> <int [3]>

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>