logo
down
shadow

Creating Summary Table from R Variables


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 : facebook icon twitter icon
Creating summary table using two separate datasets in data.table R

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

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


By : Shreu
Date : March 29 2020, 07:55 AM
should help you out Nothing reproducible here without example data. Please study https://stackoverflow.com/help/mcve
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

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

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

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
Related Posts Related Posts :
  • Authentication failure with rdrop2
  • DT data table display error
  • Issue when adding new rows (with nested dataframes within) to a dataframe
  • R-How to compare two dataframe and update list column value
  • Series vector for approximating pi
  • what is difference between "variance explained " in Random Forest and "merror" in XGBoost
  • R - Cast dataframe on unique rows - reshape2
  • ggplot2: plot correct proportions using geom_bar
  • Speedup query for R data.table - can this two-argument function be applied by group more quickly?
  • apply a function to several columns at once with mutate
  • R 'cowplot' neatly produce gridded plot with shared (common) legends and unique legends
  • Repeat R script for many times and save results to text file
  • How to negative lookbehind for special characters
  • data.table inner join produces error when no match is found
  • Create a new column base on existing column, but row above
  • Is there a way to visualize the process of source() in RStudio?
  • google places api consumes 10 request but I am doing only 1
  • Statistical mode of a categorical variable in R (using mlv)
  • Using for-loop to mutate a data.frame in r
  • Make plot with regression line for mixed model
  • Shortcut to select matces cases in R studio
  • vectoriced norm/matrix multiplication
  • Negative log10 transformation in R
  • Plot data with duplicate points
  • Visualizing crosstab tables with a plot in R - changing colours
  • How to manually modify automated numbers and labels in plot
  • How can I follow any redirections of a url in R?
  • Add jitter to box plot using markers in plotly
  • Adding an extra item to the legend
  • ggplot fills in data in the wrong order
  • Convert list to data frame
  • R: filtering by list(s) of strings and returning all results that start with the content of the lists
  • R:How to attach parts of a data frame with different headers and/or an overflowing piece of the dat frame
  • How to use 'par' for manipulating plot margins?
  • Can dplyr::case_when return mix of NAs and non-NAs?
  • Text preprocessing and topic modelling using text2vec package
  • Uploading multiple files in Shiny, process the files, rbind the results and return a download
  • R levelplot: color green-white-red (white on 0) according to one variable, but show the values of another variable
  • Why [i] doesn't point to the starting point in a vector
  • In R after generating a mvrnorm distribution, Y, what does Y[,1] do?
  • expand a data frame to have as many rows as range of two columns in original row
  • Getting started with R and CFA
  • Re order x-axis in ggplot so time goes from 12AM to 11PM in R
  • R - Automatically stack every nth column of a data frame and save them as new objects
  • How to format dplyr output in R into doubles (or other workable format)?
  • Dataframe to matrix conversion using tapply turns zeros to NAs
  • Smallest multiple of 1:20 - How can I make it quicker?
  • How to specify the size of a graph in ggplot2 independent of axis labels
  • How can I find the number of a vector's elements in another vector?
  • ROC curve from train/test set in caret R package
  • Random Forest for a mixture of categorical,numeric and "unwanted" variables which include missing values
  • extract certain data from multiple excel files with R
  • Matrix with counts of wins and losses between methods in R
  • Grouping string variables from a dataframe by best string match to make subsets
  • Reorder does not work after adding second geom_points
  • cover POS data formate to the one can apply Arules (Apriori)
  • Matching values between data frames based on overlapping dates
  • Grouped bar chart turns into stacked bar chart ggplot
  • R: How to fill in NA Values within a Column based on grouping?
  • Two action buttons, but only the first one, that is written in the server file, works?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org