C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# Creating Summary Table from R Variables

By : Luke
Date : October 20 2020, 08:10 PM
should help you out You can create multiple summary statistics with summarise, all on the same data frame:
code :
``````library(tidyverse)

NBA %>%
group_by(First..Last) %>%
summarise(sd = sd(DKP),
max = max(DKP),
min = min(DKP),
mean = mean(DKP))
``````

Share :

## Creating summary table using two separate datasets in data.table R

By : Qs F
Date : March 29 2020, 07:55 AM
this will help Language: R , Here's one way:
code :
``````DT[.(unique(CountryKey\$Country)), .N, on="Birth", by=.EACHI]
``````

## Summary table of many variables when each needs to be restricted using if

By : Shreu
Date : March 29 2020, 07:55 AM
But I would go
code :
``````gen var1_2 = var1 if restriction == 2
gen var2_3 = var2 if restriction == 3
gen var3_4 = var3 if restriction == 4
summarize var1_2 var2_3 var3_4
``````

## Creating Summary Tables with multiple variables in R

By : Howard Smith
Date : March 29 2020, 07:55 AM
Hope this helps What makes this a little more complicated is that there are values you want represented in the solution that you don't have in the dataframe, such as all values for "Company3." My solution is to create an "anchor" data frame that contains all combinations of Company and Duration then left join a summary table to that. Finally, where values are NA, set to 0.
code :
``````library(dplyr)

# Create anchor dataframe
anchor <- data.frame(Company = rep(c("Company1","Company2","Company3","Company4","Company5"),each=5),
Duration = rep(c(1:5),5),
stringsAsFactors = F)
# Summarize data
summary <- df %>%
group_by(Zone,Type,Company,Duration) %>%
summarise(stat = sum(Value)) %>% # summarise as desired
ungroup() %>%
mutate(Zone.Type =  paste0(Zone,".",Type)) %>%
select(-Zone,-Type) %>%
spread(key = Zone.Type, value = stat, fill = 0)

# Join the anchor to the summary
final <- left_join(anchor,summary,by = c("Company","Duration")) %>%
arrange(Company,Duration)

# Set all NA to 0
final[is.na(final)] <- 0
``````
``````    Company Duration Asia.1 Asia.2 Europe.1 Europe.2 USA.1 USA.2
1  Company1        1      0      0        0        0     0     0
2  Company1        2      0      0        0        0     0     0
3  Company1        3      0      0     2000        0     0     0
4  Company1        4      0      0        0     3000     0     0
5  Company1        5      0      0        0        0     0     0
6  Company2        1      0      0        0        0     0     0
7  Company2        2      0      0        0        0     0  1300
8  Company2        3      0      0        0        0  1500     0
9  Company2        4      0      0        0        0     0     0
10 Company2        5   6000      0        0        0     0     0
11 Company3        1      0      0        0        0     0     0
12 Company3        2      0      0        0        0     0     0
13 Company3        3      0      0        0        0     0     0
14 Company3        4      0      0        0        0     0     0
15 Company3        5      0      0        0        0     0     0
16 Company4        1      0      0     2000        0     0     0
17 Company4        2      0      0        0        0     0     0
18 Company4        3      0      0        0     2000     0     0
19 Company4        4      0      0        0        0     0     0
20 Company4        5      0      0        0        0     0     0
21 Company5        1      0      0        0        0     0     0
22 Company5        2      0      0        0        0     0     0
23 Company5        3      0      0        0        0     0     0
24 Company5        4      0      0        0     3000  1200     0
25 Company5        5      0   2000     1000        0     0     0
``````

## Trying to get summary variables into a table

By : Mikklynn
Date : March 29 2020, 07:55 AM
I wish did fix the issue. So I'm working on a project that looks at the spaces of different car parking spaces. So essentially, I would like the variables from summary (mean, quantile, IQR, sd, max, min, median) into a table that when I run it is comes up as a table with all the different variables for each of my Carpark spaces. , I think you want something like this:
code :
``````summary <- function(x) {
funs <- c(mean, median, sd, mad, IQR)
lapply(funs, function(f) f(x, na.rm = TRUE))
}
``````
``````sapply(mtcars, function(x) { if(is.numeric(x)) summary(x) })
``````

## Creating table of variables with specific summary statistics

By : JohnMLilley
Date : March 29 2020, 07:55 AM
this one helps. If you're using dplyr already, you can make use of long shaped data and grouping, and treat all the functions you need as summarizations. That lets you scale easily, so it's the same workflow for 3 variables as it is for 25 or 100. It also makes it relatively quick to apply whatever functions you want.
I made dummy data with x, y, and z, then bound onto it a couple rows of NAs just to show the missing value count. Gather it to long data, group by the variable, then use whatever summary functions you want. I started out the first several you named. This gives you the format you asked for.
code :
``````library(tidyverse)

tibble(
x = rnorm(100, mean = 1, sd = 1),
y = rnorm(100, mean = 10, sd = 1),
z = rexp(100, rate = 0.01)
) %>%
bind_rows(tibble(x = c(NA, NA), y = c(NA, NA), z = c(NA, NA))) %>%
gather(key = variable, value = value) %>%
group_by(variable) %>%
summarise(
count = n(),
missing = sum(is.na(value)),
share_missing = missing / count,
mean = mean(value, na.rm = T),
sd = sd(value, na.rm = T),
q1 = quantile(value, 0.25, na.rm = T)
)
#> # A tibble: 3 x 7
#>   variable count missing share_missing    mean     sd     q1
#>   <chr>    <int>   <int>         <dbl>   <dbl>  <dbl>  <dbl>
#> 1 x          102       2        0.0196   0.997  1.08   0.246
#> 2 y          102       2        0.0196   9.81   0.962  9.10
#> 3 z          102       2        0.0196 106.    90.6   39.9
``````