Hi, it looks like your dataframes got a little jumbled in the pasting. Here they are separated
My_OLR_dataframe <- structure(list(ID = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20), Group = c(1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2), Question_1 = c(4,
2, 3, 4, 1, 1, 2, 4, 4, 3, 2, 4, 1, 2, 3, 5, 3, 4, 2, 1), Question_2 = c(2,
4, 4, 1, 3, 2, 2, 4, 1, 3, 2, 5, 5, 3, 4, 1, 1, 2, 3, 2), Question_3 = c(2,
3, 1, 5, 5, 1, 1, 2, 5, 2, 1, 1, 4, 2, 5, 1, 3, 3, 4, 4), Question_4 = c(2,
1, 3, 3, 5, 4, 5, 5, 1, 3, 4, 1, 3, 5, 2, 4, 3, 1, 2, 1), Question_5 = c(4,
3, 4, 1, 4, 4, 3, 2, 4, 1, 1, 1, 4, 4, 3, 3, 3, 4, 1, 3), Question_6 = c(5,
2, 1, 4, 1, 2, 2, 2, 1, 2, 1, 4, 2, 4, 3, 4, 5, 3, 5, 1), Question_7 = c(1,
5, 4, 2, 1, 4, 2, 4, 3, 2, 2, 3, 3, 4, 4, 3, 4, 4, 4, 1), Question_8 = c(4,
1, 1, 1, 1, 4, 2, 1, 5, 2, 3, 4, 3, 1, 2, 2, 5, 4, 1, 2), Question_9 = c(2,
3, 1, 4, 4, 3, 5, 4, 1, 3, 2, 1, 5, 3, 3, 4, 1, 1, 1, 5), Question_10 = c(1,
2, 4, 4, 4, 3, 1, 2, 3, 1, 3, 2, 2, 2, 3, 3, 3, 5, 3, 3), Question_11 = c(3,
1, 3, 3, 5, 4, 2, 4, 1, 4, 5, 4, 1, 2, 2, 3, 2, 1, 2, 3), Question_12 = c(1,
1, 1, 5, 5, 3, 3, 3, 2, 3, 4, 4, 4, 1, 3, 1, 1, 2, 2, 2), Question_13 = c(2,
5, 5, 1, 1, 3, 1, 4, 5, 1, 2, 4, 1, 3, 2, 5, 2, 5, 5, 5), Question_14 = c(4,
1, 4, 1, 3, 1, 5, 4, 3, 1, 3, 4, 1, 4, 5, 3, 1, 4, 2, 1), Question_15 = c(2,
4, 1, 3, 1, 2, 2, 3, 3, 1, 5, 2, 3, 5, 5, 2, 2, 1, 2, 3)), row.names = c(NA,
-20L), class = c("tbl_df", "tbl", "data.frame"))
It looks like aaa
was identical to My_OLR_dataframe
so I've omitted it.
str(My_OLR_dataframe)
#> Classes 'tbl_df', 'tbl' and 'data.frame': 20 obs. of 17 variables:
#> $ ID : num 1 2 3 4 5 6 7 8 9 10 ...
#> $ Group : num 1 1 1 1 1 1 1 1 1 1 ...
#> $ Question_1 : num 4 2 3 4 1 1 2 4 4 3 ...
#> $ Question_2 : num 2 4 4 1 3 2 2 4 1 3 ...
#> $ Question_3 : num 2 3 1 5 5 1 1 2 5 2 ...
#> $ Question_4 : num 2 1 3 3 5 4 5 5 1 3 ...
#> $ Question_5 : num 4 3 4 1 4 4 3 2 4 1 ...
#> $ Question_6 : num 5 2 1 4 1 2 2 2 1 2 ...
#> $ Question_7 : num 1 5 4 2 1 4 2 4 3 2 ...
#> $ Question_8 : num 4 1 1 1 1 4 2 1 5 2 ...
#> $ Question_9 : num 2 3 1 4 4 3 5 4 1 3 ...
#> $ Question_10: num 1 2 4 4 4 3 1 2 3 1 ...
#> $ Question_11: num 3 1 3 3 5 4 2 4 1 4 ...
#> $ Question_12: num 1 1 1 5 5 3 3 3 2 3 ...
#> $ Question_13: num 2 5 5 1 1 3 1 4 5 1 ...
#> $ Question_14: num 4 1 4 1 3 1 5 4 3 1 ...
#> $ Question_15: num 2 4 1 3 1 2 2 3 3 1 ...
Now the next step requires some careful thought about how you want to use the new object. The layout is a poor choice for further analysis because it it untidy
(the concept that a data frame should consist of a single observation per row of one or more variables, which is what My_OLR_dataframe` is now.
On the other hand, if you want to produce a report like the screenshot, what I would suggest is to divide it into four sections, one for each group.
To get there
# OMITTED My_OLR_dataframe <- structure ...
suppressPackageStartupMessages(library(dplyr))
grp1 <- My_OLR_dataframe %>% filter(Group == 1) %>% select(-ID,-Group)%>% t() %>% as.data.frame()
grp1
#> V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11
#> Question_1 4 2 3 4 1 1 2 4 4 3 2
#> Question_2 2 4 4 1 3 2 2 4 1 3 2
#> Question_3 2 3 1 5 5 1 1 2 5 2 1
#> Question_4 2 1 3 3 5 4 5 5 1 3 4
#> Question_5 4 3 4 1 4 4 3 2 4 1 1
#> Question_6 5 2 1 4 1 2 2 2 1 2 1
#> Question_7 1 5 4 2 1 4 2 4 3 2 2
#> Question_8 4 1 1 1 1 4 2 1 5 2 3
#> Question_9 2 3 1 4 4 3 5 4 1 3 2
#> Question_10 1 2 4 4 4 3 1 2 3 1 3
#> Question_11 3 1 3 3 5 4 2 4 1 4 5
#> Question_12 1 1 1 5 5 3 3 3 2 3 4
#> Question_13 2 5 5 1 1 3 1 4 5 1 2
#> Question_14 4 1 4 1 3 1 5 4 3 1 3
#> Question_15 2 4 1 3 1 2 2 3 3 1 5
Created on 2020-03-18 by the reprex package (v0.3.0)
Of course, you can replace with column names with
colnames(grp1) <- c("Some","Data","Shown","Here"...)
It's not clear what the summary represents, and grp1
has 11 columns, which are presumably the responses. The screenshot has only the 5. Are these the counts of each category (1...5) of response? If so, work should be done back in My_OLR_dataframe
with group_by
and count
to do the summary first.