Creating new data sets from means of existing variables

Hello -

I'm a complete beginner on R but have to use it. I need to run a bunch of linear regressions on the means of a number of different variables. My raw data set contains all of my responses. I am able to create means for the different variables using Rcmdr and/or Jamovi (and copying in the script). How do I then create new variables (or new data sets?) from those means so that I can run linear regressions?

Thanks for any help!

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

Thank you, please see some sample data below. I want to work with the means of the scores for each of the items, but I don't know what the best way to do that is.

Item 1 Score Item 2 Score Item 3 score Item 4 Score Item 5 Score
870 730 40 270 800
630 710 600 560 480
60 900 540 440 350
870 610 730 200 430
350 80 610 50 560
430 710 690 620 250
880 540 970 340 640
670 600 420 700 250
310 810 60 600 410
280 350 40 680 770

You are not being very specific about the output you are looking for, Is this what you want?

library(tidyverse)

# Sample data in a copy/paste friendly format, replace this with your own data frame
sample_df <- data.frame(
     check.names = FALSE,
  `Item 1 Score` = c(870L, 630L, 60L, 870L, 350L, 430L, 880L, 670L, 310L, 280L),
  `Item 2 Score` = c(730L, 710L, 900L, 610L, 80L, 710L, 540L, 600L, 810L, 350L),
  `Item 3 score` = c(40L, 600L, 540L, 730L, 610L, 690L, 970L, 420L, 60L, 40L),
  `Item 4 Score` = c(270L, 560L, 440L, 200L, 50L, 620L, 340L, 700L, 600L, 680L),
  `Item 5 Score` = c(800L, 480L, 350L, 430L, 560L, 250L, 640L, 250L, 410L, 770L)
)

# Relevant code
sample_df %>% 
    pivot_longer(cols = everything(), names_to = "Item", values_to = "Mean_Score") %>% 
    mutate(Item = str_remove(Item, "\\s[Ss]core$")) %>% # This is just to clean the names
    group_by(Item) %>% 
    summarise(Mean_Score = mean(Mean_Score))
#> # A tibble: 5 × 2
#>   Item   Mean_Score
#>   <chr>       <dbl>
#> 1 Item 1        535
#> 2 Item 2        604
#> 3 Item 3        470
#> 4 Item 4        446
#> 5 Item 5        494

Created on 2022-03-09 by the reprex package (v2.0.1)

Note: Please notice the way I'm sharing the example with you, that would be a proper reproducible example, please read the guide on the link I gave you before and next time try to provide one.

Thank you. Yes, this is very helpful. Apologies for the poor request. I will work to do better.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.