How can I merge multiple dataframes with the same column names got as a result of applying MVN::mvn?

Viewed 17

Applying mvn to iris requires subsetting by the Species variable.

However, the result of this package is a nested of named lists, finally containing a dataframe with p-values and metrics for each subset.

I find this uncomfortable to read and to process, so I want to merge all this almost equally named tables into one.

I haven't a found a merge function for multiple tables at once.

Therefore, I tried with Reduce() as suggested in other similar questions.

  • The first applies a merge() correctly to pairs of dataframes.
  • merging is done with merge() with 2 tables at the time.

The problems are:

  • Naming of the classes (Species) are lost
  • Results gets mixed
  • I am forced to specify either univariate o multivariate, and call 2 times.

I would like just a resulting dataframe with, 1 column for the classes, 1 for the univariate/multivariate, and the rest merged by column names.

mvn_results = MVN::mvn( iris, subset='Species', mvnTest = "hz" )
mvn_results 

Resulting:

$multivariateNormality
$multivariateNormality$setosa
$multivariateNormality$versicolor
$multivariateNormality$virginica

$univariateNormality
$univariateNormality$setosa
$univariateNormality$versicolor
$univariateNormality$virginica

$Descriptives
$Descriptives$setosa
$Descriptives$versicolor
$Descriptives$virginica

And tables with repeated structure like this: enter image description here enter image description here enter image description here

I tried this:

mvn_merged <- Reduce(function(x, y) 
  merge( x, y, all=TRUE), mvn_results$univariateNormality )
mvn_merged

which produced the next result:

enter image description here

0 Answers
Related