Applying functions (e.g. mean, sd) across variables
I'd like to apply some standard functions across rows. For example, to get the mean of some scale items on a survey I could use the R code (Q1 + Q2 + Q3) / 3, but if any one of those is missing, the result would be missing. I'd like the result to be the mean of the non-missing values. I'd like to do this in general, so that I could get the median, sd, etc. Is this possible? Thanks!

Comments
I know that this is unlikely to be helpful, as I am not savvy in either DataMatrix (1) or R, but doesn't DataMatrix have NumPy as dependency? In numpy, you could exclude the missing values with
np.nanmean()or filter out the missing values altogether withnp.isnan(). Alternatively, most functions in Pandas -which I tend to use most- exclude missing values by default.(1) I wasn't sure if your question was only related to R or also DataMatrix, given its category.
Hi Bob,
Like @cesco, I'm not sure whether your question concerns the Python
DataMatrixlibrary or something else (perhaps an R data frame?). However, if this is aboutDataMatrix, then you can simply use themeanproperty of a column, which will only use non-nan numeric values.For more information, see also:
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!