-1

A data sets looks like this:

name    amt
lucy    100
mark    234
andy    456
wendy   456
lucy    34
wendy   345

How to make it in the form below by using R or SAS?

name    amt
lucy    134
mark    234
andy    456
wendy   801
thelatemail
  • 91,185
  • 12
  • 128
  • 188
Amanda
  • 63
  • 1
  • 7

1 Answers1

0

In R, we can do this with a number of options. The base R includes aggregate

aggregate(amt~name, df, sum)

Or xtabs

as.data.frame(xtabs(amt~name, df))

Or with packages like dplyr

library(dplyr)
df %>%
   group_by(name) %>%
   summarise(amt = sum(amt))

Or data.table

library(data.table)
setDT(df)[, .(amt = sum(amt)), by = name]
akrun
  • 874,273
  • 37
  • 540
  • 662