0

I'm currently working with csv's with data about test participants on a diet program. One CSV has the the partcipants information 'suubject id', chosen group', 'extra calories' etc.

enter image description here

The second set of csv's are about the different diet groups, meals, calories etc. (of which there are 10)

enter image description here

My task was to find the total calories of each group then find the total calories of each participants chosen group.

To get the total calories of each group I just made a variable that summed the total calories of each group

 one <- sum(groupOne$calories)

Then I cleaned the data up a bit in the participants file by removing the 'g' in the row name.

I would ideally like to get some output that has the participants subjectID and their the total calories of their group. Something like below:

 |SubjectID||Group||Groups Total Calories|
   1          G3        100cal
   2          G6        200cal

After that I'm kind of stuck, I don't quite know how to group the two together to together and spit out some data that matches the participants to the groups to output a clean display of the participants subjectId, their group and the total calories of that group.

Ibbylun
  • 73
  • 1
  • 10
  • It is probably best to share the output of `dput(df)` than a picture. In addition, if you clearly specify desired output, a response might be quicker. – deepseefan Nov 02 '19 at 02:09
  • 1
    Thanks for the feedback. I'll try and clean up the question – Ibbylun Nov 02 '19 at 02:13
  • There is alot of output in the dput(df) so its kind of hard to copy and paste in – Ibbylun Nov 02 '19 at 02:50
  • How do you know which group belong to which meal category? – deepseefan Nov 02 '19 at 02:59
  • I have 10 csv's all different groups. I.e. 'group1.csv' 'group2.csv' etc – Ibbylun Nov 02 '19 at 03:02
  • If we focus on the above two tables, is there a column shared between the two? – deepseefan Nov 02 '19 at 03:03
  • No. I inputted the data like this group_files <- c("data/Group1.csv", "data/Group2.csv ", "data/Group3.csv ", "data/Group4.csv ", "data/Group5.csv ", "data/Group6.csv ", "data/Group7.csv ", "data/Group8.csv ", "data/Group9.csv ", "data/Group10.csv" ) participants_file <- read_csv("data/participants.csv") – Ibbylun Nov 02 '19 at 03:04
  • and thats where my problem lies as I don't know how to make the connection between the two – Ibbylun Nov 02 '19 at 03:05
  • 1
    For example, the information contained within `group1.csv` is about `G1` only? – deepseefan Nov 02 '19 at 03:14
  • Yeh thats true. So something like group1 <- read_csv('group1.csv'). Then group1$Group <- g1 ?? Or would I have to turn it into a dataframe first? – Ibbylun Nov 02 '19 at 03:16
  • 1
    Yes, make it a character `group1$Group <- "G1"` otherwise it assumes you're trying to replace with an object `g1`. . – deepseefan Nov 02 '19 at 03:17
  • Awesome. Thank you. I'll try that now and report back – Ibbylun Nov 02 '19 at 03:19
  • @lbbylun You may also provide `head(dput(dfr))`. Read: [How to make a great R MCVE](https://stackoverflow.com/a/5963610/6574038). – jay.sf Nov 02 '19 at 04:36

0 Answers0