[R] couple of how-to-do it in R questions regarding corelations and mean and SD of likert items
ruipbarradas at sapo.pt
Tue Mar 6 17:21:52 CET 2018
You can use function apply() to do what you want without needing to type
the same 10 times. Here is a reproducible example.
set.seed(2234) # Make the results reproducible
# Make up some data
dv <- rnorm(100)
iv <- replicate(10, rnorm(100))
apply(iv, 2, cor, dv)
Now suppose you have a matrix (or data.frame)
dat <- cbind(dv, iv)
apply(dat[, -1], 2, cor, dat[, 1])
Hope this helps,
On 3/6/2018 12:03 PM, faiz rasool wrote:
> Dear list, I have the following how-to-do it in R, questions.
> Suppose I have ten independent variables, and one dependent variable.
> I want to find the Pearson correlation of all the IVs with the DV, but
> not the correlation between the IVs.
> What I know so far, about R, that I have to type the cor () function
> ten times, each time requesting for a correlation between one IV and
> the DV.
> I was wondering that is there a way that I can accomplish what I want
> with a single function or a fewer line of codes.
> My final goal is to create a table in Microsoft word comprising of ten
> rows, each row for each independent variable and its correlation with
> the DV.
> Based on what I know, I’ll be typing cor (IV,,DV), ten times, and then
> typing the values in the table in MS Word.
> Secondly, I would like to create a table that provides the details of
> means and standard deviations, of multiple variables.
> The variables are ratings scores of likert type items. What I’d
> like to do is to construct a table, where each row has the question,
> its mean and standard deviation. I know that using the psych package,
> I can have the mean of each item in the scale, but, how to develop a
> table that has the item, mean, and SD on a same row? I do not know.
> Thank you for reading my questions.
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help