# Simple descriptive statistics

#1

Dear R Geeks
i'm a beginner with R and trying to apply all my simple excel tasks in R . so need your usual support please
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 ?

#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

#6

#7

Done Appreciated

#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')".