Simple descriptive statistics


#1

Dear R Geeks :slight_smile:
i’m a beginner with R and trying to apply all my simple excel tasks in R . so need your usual support please :slight_smile:
If i have a data frame contains data of survey responses as follows

ID     Date                  CSI                Phonenumber
123    1/10/2017 12:23:00    Dissatisfied       123456
456    15/3/2017  15:41:22   Very Dissatisfied  564613
789    23/3/2018  10:21:22   Satisfied          899989
741    11/12/2017 09:12:22   Very Dissatisfied  8989845

What i want is to count those who are Dissatisfied && Very Dissatisfied per week number.
Where i need an output table same as follows

Week number            Total Responses    Dissatisfied+Very Dissatisfied   percentage
week number of date    4                  2                                50%

How can i do this ?
Appreciate your support my firends


#2

you could do something like this:

library(tidyverse)
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#> 
#>     date

data <- read.table(text = "123    '1/10/2017 12:23:00'    Dissatisfied       123456
456    '15/3/2017  15:41:22'   'Very Dissatisfied'  564613
789    '23/3/2018  10:21:22'   Satisfied          899989
741    '11/12/2017 09:12:22'   'Very Dissatisfied'  8989845",
                   col.names = c("ID", "Date", "CSI", "Phonenumber"))



data %>%
  mutate(Date = lubridate::dmy_hms(Date),
         week = lubridate::week(Date),
         year = lubridate::year(Date)) %>%
  group_by(year, week) %>%
  summarize(total_responses = n(),
            count_dis = sum(CSI %in% c("Dissatisfied", "Very Dissatisfied")),
            perc_dis = mean(CSI %in% c("Dissatisfied", "Very Dissatisfied")))
#> # A tibble: 4 x 5
#> # Groups:   year [?]
#>    year  week total_responses count_dis perc_dis
#>   <dbl> <dbl>           <int>     <int>    <dbl>
#> 1  2017  11.0               1         1     1.00
#> 2  2017  40.0               1         1     1.00
#> 3  2017  50.0               1         1     1.00
#> 4  2018  12.0               1         0     0

Created on 2018-03-02 by the reprex package (v0.2.0).

As a note, it is much easier to help you if you provide a reprex of your problem:


#3

Hi,

Unless this is a problem with the RStudio IDE, it really doesn’t belong in the #rstudio-ide topic. From a quick look, I’d saw this one probably falls under #general. If you could please change it, that would be great. It also ensures that the right people see it, thereby increasing your chances of getting the help you need.

Thanks.


#4

Thank you all for your usual support. The answer is very awesome. And I changed the topic to general


#5

@tbradley thanks a million :slight_smile:


#6

If you question has been answered, please mark the post that answered it as correct, thanks!


#7

Done Appreciated :slight_smile:


#8

when i’m trying to solve this problem but data was stored at CSV file. used only read.csv
but resulted in an error.
Error in mutate_impl(.data, dots) :
Evaluation error: no applicable method for ‘group_by_’ applied to an object of class “c(‘double’, ‘numeric’)”.
In addition: Warning message:
All formats failed to parse. No formats found.
Would you please suggest my friend. Appreciate your kind support that i’m a new beginner with R, So Appreciate your bearing with me :slight_smile: @tbradley