Skip to content
Back to formatted view

Raw Message

Message-ID: <20200506223515.GB1249402@posteo.no>
Date: 2020-05-06T22:35:15Z
From: Rasmus Liland
Subject: How to combine two rows in a data table into a third new row, such that the values in the row are added together in the new row?
In-Reply-To: <220eb24467d947438526d4961cff8e15@SRVEXCHCM1302.precheza.cz>

On 2020-05-06 09:13 +0000, PIKAL Petr wrote:
> Maybe aggregate?

Hi!  I agree aggregate is an elegant solution 
for this, so I continued your example a bit:

dt_count <- '"","STATUS","N"
"1","Resolved",650
"2","Assigned",135
"3","Closed",530
"4","In Progress",56
"5","Pending",75
"6","Cancelled",20'
dt_count <- read.csv(text=dt_count)

dt_count[
  dt_count$STATUS %in%
  c("Resolved", "Closed"),
  "STATUS"] <-
  "Resolved/Closed"
aggregate(
  x=list("N"=dt_count$N),
  by=list("STATUS"=dt_count$STATUS),
  FUN=sum)

Best,
Rasmus

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20200507/5178fe64/attachment.sig>