0

Using a dataframe, df, containing several S&P500 stocks monthly returns, I generated the inputs required for the multivariate random normal distribution function rmsn in the R package sn:

library(moments)
library(sn)
muvec = apply(df, 2, mean)
covmat = cov(df)
skew = apply(df, 2, skewness)
rmsn(100, muvec, covmat, skew)

However, the randomly generated numbers do not contain the original column headers in my input vectors (e.g. "A", "B", "C"). Instead, the output of rmsn contains generic names ("V1", "V2", "V3"). Is there a way to ensure that my original column headers are passed through into the output?

Output of random number generation

sjedi
  • 43
  • 1
  • 7

1 Answers1

0

The output of rmsn is a matrix with no names and I am assuming you are using as.data.frame to convert it to a dataframe which gives it the default/geenric column names.

I think the only way is to assign the column names from df

out <- as.data.frame(sn::rmsn(100, muvec, covmat, skew))
names(out) <- names(df)
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213