I'm currently analysing data for a student project. During the analysis, I combined two variables into one with cbind():
interpas$GA02_01 <- cbind(interpas$LP02_01, interpas$ST02_01)
The two variables LP02_01 and ST02_01 are measuring the same questions but for different media-formats. There's no overlapping between the two. The structure is like this:
LP02_01 ST02_01
1 NA
NA 2
NA 5
4 NA
So they just get combined. When I calculate the mean with the built-in mean() function from R, I get the mean of the new variable GA02_01.
But when I'um using the mean function of the package psych, or any other function for descriptive statistics (like describe) from this package, it's calculating the two variables LP02_01 and ST02_01 still seperately. Like this:
> describe(interpas$GA02_01)
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 151 3.62 1.89 4 3.59 1.48 1 7 6 0.00 -1.24 0.15
X2 2 63 2.70 1.92 2 2.45 1.48 1 7 6 0.85 -0.64 0.24
Does anyone know a solution to this? Unfortunately, I need the descriptive functions skew and kurtosi from the psych package for further analysis and a function to check for normal distribution.
Thanks a lot!
You just need to unlist
your data frame. However make sure thatr you are choosing the desired columns in the correct (for your usecase) manner. For example, when you use cbind
, you create matrix. You can just use indexing, i.e. df[1:2]
(for first and second columns) or by name, i.e. df[,c("LP02_01", "ST02_01")]
. That way you result with a data frame object. Then you can just unlist
and describe()
, i.e.
psych::describe(unlist(interpas[, c("LP02_01", "ST02_01")]))
# vars n mean sd median trimmed mad min max range skew kurtosis se
#X1 1 4 3 1.83 3 3 2.22 1 5 4 0 -2.24 0.91