1

I'm. trying to group the transactions that fall under each date as a day eg for all the transactions that fall under 13/02/2021 should be grouped as Wednesday

Recipient Network Provider Type FaceValue Date
24254432670 Amtel Gold Airtime 350 15/02/2021 23:59
24254432670 Amtel Gold Airtime 300 15/02/2021 23:56
24254432670 Amtel Gold Airtime 200 15/02/2021 23:54
24254432670 Amtel Gold Airtime 2200 14/02/2021 23:54
24254432670 Amtel Gold Airtime 500 14/02/2021 23:54
24254432670 Amtel Gold Airtime 100 14/02/2021 23:54
24254432670 Amtel Gold Airtime 200 14/02/2021 23:54
24254432670 Amtel Gold Airtime 1200 14/02/2021 23:54
24254432670 Amtel Gold Airtime 200 14/02/2021 23:54
24254432670 Amtel Gold Airtime 100 14/02/2021 23:54
24254432670 Amtel Gold Airtime 1500 13/02/2021 23:46
24254432670 Amtel Gold Airtime 200 13/02/2021 23:46
24254432670 Amtel Gold Airtime 2000 13/02/2021 23:46
24254432670 Amtel Gold Airtime 500 13/02/2021 23:46
24254432670 Amtel Gold Airtime 300 13/02/2021 23:46
24254432670 Amtel Gold Airtime 400 13/02/2021 23:46
24254432670 Amtel Gold Airtime 2000 13/02/2021 23:46
24254432670 Amtel Gold Airtime 100 13/02/2021 23:46
24254432670 Amtel Gold Airtime 1000 15/02/2021 23:40
8104573975 Amtel GOLAD Airtime 2000 15/02/2021 23:40
AnilGoyal
  • 25,297
  • 4
  • 27
  • 45

2 Answers2

0
# your data
df <- tribble(
  ~Recipient, ~Network, ~Provider, ~Type, ~FaceValue, ~Date,
"24254432670", "Amtel", "Gold", "Airtime", "350", "15/02/2021 23:59", 
  "24254432670", "Amtel", "Gold", "Airtime", "300", "15/02/2021 23:56", 
  "24254432670", "Amtel", "Gold", "Airtime", "200", "15/02/2021 23:54", 
  "24254432670", "Amtel", "Gold", "Airtime", "2200", "14/02/2021 23:54", 
  "24254432670", "Amtel", "Gold", "Airtime", "500", "14/02/2021 23:54", 
  "24254432670", "Amtel", "Gold", "Airtime", "100", "14/02/2021 23:54", 
  "24254432670", "Amtel", "Gold", "Airtime", "200", "14/02/2021 23:54", 
  "24254432670", "Amtel", "Gold", "Airtime", "1200", "14/02/2021 23:54", 
  "24254432670", "Amtel", "Gold", "Airtime", "200", "14/02/2021 23:54", 
  "24254432670", "Amtel", "Gold", "Airtime", "100", "14/02/2021 23:54", 
  "24254432670", "Amtel", "Gold", "Airtime", "1500", "13/02/2021 23:46", 
  "24254432670", "Amtel", "Gold", "Airtime", "200", "13/02/2021 23:46", 
  "24254432670", "Amtel", "Gold", "Airtime", "2000", "13/02/2021 23:46", 
  "24254432670", "Amtel", "Gold", "Airtime", "500", "13/02/2021 23:46", 
  "24254432670", "Amtel", "Gold", "Airtime", "300", "13/02/2021 23:46", 
  "24254432670", "Amtel", "Gold", "Airtime", "400", "13/02/2021 23:46", 
  "24254432670", "Amtel", "Gold", "Airtime", "2000", "13/02/2021 23:46", 
  "24254432670", "Amtel", "Gold", "Airtime", "100", "13/02/2021 23:46", 
  "24254432670", "Amtel", "Gold", "Airtime", "1000", "15/02/2021 23:40", 
  "8104573975", "Amtel", "GOLAD", "Airtime", "2000", "15/02/2021 23:40")

# manipulate and create new column where 13/02/2021 is Saturday
df <- df %>% 
  mutate(Recipient=as.numeric(Recipient),
         FaceValue = as.numeric(FaceValue),
         Date = format(as.POSIXct(strptime(Date,"%d/%m/%Y %H:%M",tz="")) ,format = "%d/%m/%Y"),
         NewCol = case_when(Date == "13/02/2021" ~ "Saturday")
         )

enter image description here

TarJae
  • 72,363
  • 6
  • 19
  • 66
0

EDIT In view of another question

library(dplyr)

df %>% mutate(DAY = as.Date(Date, "%d/%m/%Y"),
              DAY = paste0('Day', dense_rank(DAY)))

# A tibble: 20 x 7
   Recipient   Network Provider Type    FaceValue Date             DAY  
   <chr>       <chr>   <chr>    <chr>   <chr>     <chr>            <chr>
 1 24254432670 Amtel   Gold     Airtime 350       15/02/2021 23:59 Day3 
 2 24254432670 Amtel   Gold     Airtime 300       15/02/2021 23:56 Day3 
 3 24254432670 Amtel   Gold     Airtime 200       15/02/2021 23:54 Day3 
 4 24254432670 Amtel   Gold     Airtime 2200      14/02/2021 23:54 Day2 
 5 24254432670 Amtel   Gold     Airtime 500       14/02/2021 23:54 Day2 
 6 24254432670 Amtel   Gold     Airtime 100       14/02/2021 23:54 Day2 
 7 24254432670 Amtel   Gold     Airtime 200       14/02/2021 23:54 Day2 
 8 24254432670 Amtel   Gold     Airtime 1200      14/02/2021 23:54 Day2 
 9 24254432670 Amtel   Gold     Airtime 200       14/02/2021 23:54 Day2 
10 24254432670 Amtel   Gold     Airtime 100       14/02/2021 23:54 Day2 
11 24254432670 Amtel   Gold     Airtime 1500      13/02/2021 23:46 Day1 
12 24254432670 Amtel   Gold     Airtime 200       13/02/2021 23:46 Day1 
13 24254432670 Amtel   Gold     Airtime 2000      13/02/2021 23:46 Day1 
14 24254432670 Amtel   Gold     Airtime 500       13/02/2021 23:46 Day1 
15 24254432670 Amtel   Gold     Airtime 300       13/02/2021 23:46 Day1 
16 24254432670 Amtel   Gold     Airtime 400       13/02/2021 23:46 Day1 
17 24254432670 Amtel   Gold     Airtime 2000      13/02/2021 23:46 Day1 
18 24254432670 Amtel   Gold     Airtime 100       13/02/2021 23:46 Day1 
19 24254432670 Amtel   Gold     Airtime 1000      15/02/2021 23:40 Day3 
20 8104573975  Amtel   GOLAD    Airtime 2000      15/02/2021 23:40 Day3

Earlier answer

why not simply this, as already suggested by Ronak in his comment? (assuming df your data)

#Either
df$DAY <- weekdays(as.Date(df$Date, "%d/%m/%Y"))

#OR
dplyr::mutate(df, DAY = weekdays(as.Date(Date, "%d/%m/%Y")))

# A tibble: 20 x 7
   Recipient   Network Provider Type    FaceValue Date             DAY     
   <chr>       <chr>   <chr>    <chr>   <chr>     <chr>            <chr>   
 1 24254432670 Amtel   Gold     Airtime 350       15/02/2021 23:59 Monday  
 2 24254432670 Amtel   Gold     Airtime 300       15/02/2021 23:56 Monday  
 3 24254432670 Amtel   Gold     Airtime 200       15/02/2021 23:54 Monday  
 4 24254432670 Amtel   Gold     Airtime 2200      14/02/2021 23:54 Sunday  
 5 24254432670 Amtel   Gold     Airtime 500       14/02/2021 23:54 Sunday  
 6 24254432670 Amtel   Gold     Airtime 100       14/02/2021 23:54 Sunday  
 7 24254432670 Amtel   Gold     Airtime 200       14/02/2021 23:54 Sunday  
 8 24254432670 Amtel   Gold     Airtime 1200      14/02/2021 23:54 Sunday  
 9 24254432670 Amtel   Gold     Airtime 200       14/02/2021 23:54 Sunday  
10 24254432670 Amtel   Gold     Airtime 100       14/02/2021 23:54 Sunday  
11 24254432670 Amtel   Gold     Airtime 1500      13/02/2021 23:46 Saturday
12 24254432670 Amtel   Gold     Airtime 200       13/02/2021 23:46 Saturday
13 24254432670 Amtel   Gold     Airtime 2000      13/02/2021 23:46 Saturday
14 24254432670 Amtel   Gold     Airtime 500       13/02/2021 23:46 Saturday
15 24254432670 Amtel   Gold     Airtime 300       13/02/2021 23:46 Saturday
16 24254432670 Amtel   Gold     Airtime 400       13/02/2021 23:46 Saturday
17 24254432670 Amtel   Gold     Airtime 2000      13/02/2021 23:46 Saturday
18 24254432670 Amtel   Gold     Airtime 100       13/02/2021 23:46 Saturday
19 24254432670 Amtel   Gold     Airtime 1000      15/02/2021 23:40 Monday  
20 8104573975  Amtel   GOLAD    Airtime 2000      15/02/2021 23:40 Monday
AnilGoyal
  • 25,297
  • 4
  • 27
  • 45