code: def _long_to_wide_rm(data, dv=None, within=None, subject=None):
      """Convert long-format dataframe to wide-format.
      This internal function is used in pingouin.epsilon and pingouin.sphericity.
      """
      # Check that all columns are present
      assert dv in data.columns, "%s not in data" % dv
      assert data[dv].dtype.kind in "bfiu", "%s must be numeric" % dv
      assert subject in data.columns, "%s not in data" % subject
      assert not data[subject].isnull().any(), (
          "Cannot have missing values in %s" % subject
      )
      if isinstance(within, (str, int)):
          within = [within]  # within = ['fac1'] or ['fac1', 'fac2']
      for w in within:
          assert w in data.columns, "%s not in data" % w
      # Keep all relevant columns and reset index
      data = data[_fl([subject, within, dv])]
      # Convert to wide-format + collapse to the mean
      data = pd.pivot_table(
          data,
          index=subject,
          values=dv,
          columns=within,
          aggfunc="mean",
          dropna=True,
          observed=True,
      )
      return data
  
file_path: pingouin/pingouin/distribution.py
imports: import warnings
  import scipy.stats
  import numpy
  import pandas
  from collections import namedtuple
  from pingouin.utils import _flatten_list
  from pingouin.utils import remove_na, _postprocess_dataframe
label_desc: Use image node_id 6 for calling a global function with example usage: _long_to_wide_rm(data, dv, within, subject) and returns: data