简体   繁体   中英

Reshaping and calculation of data in R

I am new to R and I would like to use it to write a simple code to visualize the Defect removal efficiency for software defect (Fixed defects / Unresolved defects) * 100 based on the priority of the bugs

I have exported some data sample from Jira:

Priority    Resolution  Created     Resolved
P3          Unresolved  28.02.2017  28.02.2017
P3          Unresolved  28.02.2017  28.02.2017
P1             Fixed    27.02.2017  06.03.2017
P2             Fixed    27.02.2017  14.03.2017
P1          Unresolved  24.02.2017  13.03.2017
P1          duplicate   21.02.2017  02.03.2017
P1             Fixed    24.02.2017  07.03.2017

I would like to reshape this table and at the same time do some calculations. This is very easy using excel pivot tables but I would like to script it with R

Expected output:

Resolution  P1  P2  P3  Grand Total
duplicate   2               2
Fixed       4   4   1       9
Unresolved  2   2   4       8
Grand Total 8   6   5       19

Also, I would like to see the trend of the resolution (Something like the following)

Dates   P1 unresolved   P1 fixed    P1 DRE, %          P2 unresolved    P2 fixed    P2 DRE, %
date1          5           0             0%                   20          3           15%
date1 + 7      6           2            33%                   37          4           11%
date1 + 14     9           3            33%                   40          4           10%

How this could be achieved by R programming?

These functions from the janitor package mimic Excel's PivotTable:

library(janitor)
dat %>% 
  tabyl(Resolution, Priority) %>%
  adorn_totals(c("row", "col"))

 Resolution P1 P2 P3 Total
  duplicate  1  0  0     1
      Fixed  2  1  0     3
 Unresolved  1  0  2     3
      Total  4  1  2     7

Data used:

dat <- read.table(text = "Priority    Resolution  Created     Resolved
P3          Unresolved  28.02.2017  28.02.2017
                  P3          Unresolved  28.02.2017  28.02.2017
                  P1             Fixed    27.02.2017  06.03.2017
                  P2             Fixed    27.02.2017  14.03.2017
                  P1          Unresolved  24.02.2017  13.03.2017
                  P1          duplicate   21.02.2017  02.03.2017
                  P1             Fixed    24.02.2017  07.03.2017", header = TRUE)

Here is an answer for the first part using just table. I saved your data into a file in the same directory, comma-separating the values.

data = read.csv('jira_data.csv')
new_data = table(data$Resolution, data$Priority)
new_data = addmargins(new_data)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM