1
votes

I have a file with 30 variables and 2000 individual. But a summary would be something like as:

  Name Farm milk protein fat dim data 
  1110 PE   10.3  3,7    3.6 146 06/07/20
  3322 PE   18.3  3,3    3.9 158 06/03/20 
  1125 PE   22.3  3,4  4.6 210 12/04/20 
  1777 PE   14.3  3,0    4.2 100 28/04/20
  8970 PE   17.3  3,2    3.6 185 14/06/20

I need:

  1. Calculate for all the variables mean, median, min, max, quartiles and group all the results into a unique/single table, I used three options:
sapply (fenotipi2, summary) R ##print only two columns with all values ​​together
library(purrr) 
library(dplyr)

phenotype2 %>% 
    map (~ summary (.)) %>%
    rbind.data.frame 
## Error in rbind.data.frame(.): 
##       invalid list argument: all variables should have the same length
library(dplyr)
library(tidyr) 
phenotype2 %>% 
    pivot_longer(everything()) %>%
    summarize_at(vars (value), list(Min = min, Mean = mean, 
                                    Max = max, Sd = sd))  
## A tibble: 1 x 4
## Min Mean Max Sd   <dbl> <dbl> <dbl> <dbl> 1 NA NA NA NA
  1. I must also do all the histograms and distributions for continuous variables in one step, I used
require(MVN)
    
result = mvn(data = fenotipi2 [-4], subset = "Species", mvnTest = "hz",
                 univariateTest = "AD", univariatePlot = "histogram",
                 multivariatePlot = "qq", multivariateOutlierMethod = "adj",
                 showOutliers = TRUE, showNewData = TRUE)

I don't get the desired results.

1
summary output depends on the class of the column. In the code, there are two datasets phenotype2 and fenotipi2. which one of them is the data showedakrun
I am sorry, fenotipi2 = phenotype2..is the same fileJohanna Ramirez
There are some packages for dealing with exploratory data stuff. You may use Hmisc::describe(fenotipi2)akrun
I find dfSummary from summarytools package very useful for quick exploration of many variablesWaldi
@JohannaRamirez I understand that the results are not exactly in a correct tabular format. One option if you want to keep it as such is capture.output(Hmisc::describe(fenotipi2), file = "yourfile.txt")akrun

1 Answers

1
votes

We could use describe from Hmisc and then write it to a file with capture.output

capture.output(Hmisc::describe(fenotipi2), file = "yourfile.txt")