0

What I want to do is create a new column that split task billable and allocate taskHRS to that columns (cast) and allocate the hours into true and false without affecting the other columns.

Code that I am using but doesn't get the desired outcome:

 Exp <- Timesheets %>%
     mutate(taskDate = as.Date(taskDate)) %>%
     mutate(taskMinutes = as.numeric(taskMinutes)) %>%
     select('jobID', 'jobTaskID', 'taskStaffName', 'taskDate', 'taskBillable','taskMinutes', 'which_payday') %>%
     group_by(jobID, taskStaffName, taskDate, taskBillable, which_payday) %>%
     summarise(taskHRS = sum(taskMinutes/60)) %>%
     filter(which_payday %in% c('ThisFN'))
print(Exp)

Exp <- Exp %>%
cast(taskStaffName ~ taskBillable ~ jobID, value = 'taskHRS')

Desired Outcome Sample:

JobID  taskStaffName  taskDate   true false which_payday Budget
W20100        L       2/10/2018    2     1   ThisFN       80

Data Sample:

jobID   taskStaffName taskDate   taskBillable which_payday taskHRS Budget
       <chr>   <chr>         <date>     <chr>        <chr>          <dbl>  <dbl>
     1 W210125 L             2018-11-13 true         ThisFN           1.5     80
     2 W210125 R             2018-11-12 true         ThisFN           2       80
     3 W210125 R             2018-11-13 true         ThisFN           2       80
     4 W210125 T             2018-11-13 true         ThisFN           2       80
     5 W210233 C             2018-11-12 true         ThisFN           6       80
luis vergara
  • 131
  • 1
  • 9
  • 1
    _"doesn't work in R 3.5.1"_ is making a _pretty broad & definitive_ statement that the error is in R vs your code. Please explain how you came to that _definitive_ conclusion? – hrbrmstr Nov 14 '18 at 02:50
  • It was my mistake, I do have reshape but still facing this problem that I couldn't keep some of the data – luis vergara Nov 14 '18 at 04:53
  • I'd counsel you to spell the package name correctly. – Hugh Nov 14 '18 at 04:53
  • I know, that was my mistake. However, still don't know how to get my desired outcome. If anyone can help me I would appreciate it – luis vergara Nov 14 '18 at 04:58

1 Answers1

0

Well, I found a solution for this problem. I have create the following code that achieve my desired outcome.

library(tidyr)

 Exp <- Timesheets %>%
     mutate(taskDate = as.Date(taskDate)) %>%
     mutate(taskMinutes = as.numeric(taskMinutes)) %>%
     select('jobID', 'jobTaskID', 'taskStaffName', 'taskDate', 'taskBillable','taskMinutes', 'which_payday') %>%
     group_by(jobID, taskStaffName, taskDate, taskBillable, which_payday) %>%
     summarise(taskHRS = sum(taskMinutes/60)) 

 library(tidyr)    

Exp <- Exp %>%
     spread(taskBillable, taskHRS)

I hope this can help anyone that is dealing with a similar problem.

The outcome that I got is as I want it

JobID  taskStaffName  taskDate   true false which_payday Budget
W20100        L       2/10/2018    2     1   ThisFN       80*
luis vergara
  • 131
  • 1
  • 9