diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..339143f Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b6a065 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.Rproj.user +.Rhistory +.RData +.Ruserdata diff --git a/Class 7 Instructions.Rmd b/Class 7 Instructions.Rmd index 5ae641a..948235d 100644 --- a/Class 7 Instructions.Rmd +++ b/Class 7 Instructions.Rmd @@ -59,7 +59,7 @@ instructor_data <- spread(data_long, variables, measure) ##Now we have a workable instructor data set!The next step is to create a workable student data set. Upload the data "student_activity.csv". View your file once you have uploaded it and then draw on a piece of paper the structure that you want before you attempt to code it. Write the code you use in the chunk below. (Hint: you can do it in one step) ```{r} - +student_wide <- spread(student_activity, variable, measure) ``` ##Now that you have workable student data set, subset it to create a data set that only includes data from the second class. @@ -75,7 +75,7 @@ student_data_2 <- dplyr::filter(student_data, date == 20160204) Now subset the student_activity data frame to create a data frame that only includes students who have sat at table 4. Write your code in the following chunk: ```{r} - +student_table4 <- dplyr::filter(student_wide, table == 4) ``` ##Make a new variable @@ -89,7 +89,7 @@ instructor_data <- dplyr::mutate(instructor_data, total_sleep = s_deep + s_light Now, refering to the cheat sheet, create a data frame called "instructor_sleep" that contains ONLY the total_sleep variable. Write your code in the following code chunk: ```{r} - +instructor_sleep <- dplyr::select(instructor_data, total_sleep) ``` Now, we can combine several commands together to create a new variable that contains a grouping. The following code creates a weekly grouping variable called "week" in the instructor data set: @@ -100,7 +100,7 @@ instructor_data <- dplyr::mutate(instructor_data, week = dplyr::ntile(date, 3)) Create the same variables for the student data frame, write your code in the code chunk below: ```{r} - +student_wide <- dplyr::mutate(student_wide, week = dplyr::ntile(date, 3)) ``` ##Sumaraizing @@ -111,13 +111,14 @@ student_data %>% dplyr::summarise(mean(motivation)) #That isn't super interesting, so let's break it down by week: -student_data %>% dplyr::group_by(date) %>% dplyr::summarise(mean(motivation)) +student_data ``` Create two new data sets using this method. One that sumarizes average motivation for students for each week (student_week) and another than sumarizes "m_active_time" for the instructor per week (instructor_week). Write your code in the following chunk: ```{r} - +student_week <- student_wide %>% dplyr::group_by(week) %>% dplyr::summarise(mean(motivation)) +instructor_week <- instructor_data %>% dplyr::group_by(week) %>% dplyr::summarise(mean(m_active_time)) ``` ##Merging @@ -131,6 +132,11 @@ merge <- dplyr::full_join(instructor_week, student_week, "week") Visualize the relationship between these two variables (mean motivation and mean instructor activity) with the "plot" command and then run a Pearson correlation test (hint: cor.test()). Write the code for the these commands below: ```{r} +plot(merge$`mean(m_active_time)`, merge$`mean(motivation)`) +cor.test(merge$`mean(m_active_time)`, merge$`mean(motivation)`) + ### Or the opposite, for the same correlation results but different plot view. ### + plot(merge$`mean(motivation)`, merge$`mean(m_active_time)`) + cor.test(merge$`mean(motivation)`, merge$`mean(m_active_time)`) ``` diff --git a/Rplot.png b/Rplot.png new file mode 100644 index 0000000..b3a5396 Binary files /dev/null and b/Rplot.png differ diff --git a/Rplot01.png b/Rplot01.png new file mode 100644 index 0000000..e2ea792 Binary files /dev/null and b/Rplot01.png differ diff --git a/instructor_activity_wide.csv b/instructor_activity_wide.csv index 69c31d1..3a543f4 100644 --- a/instructor_activity_wide.csv +++ b/instructor_activity_wide.csv @@ -1 +1,16 @@ -variables,X20160121,X20160122,X20160123,X20160124,X20160125,X20160126,X20160127,X20160128,X20160129,X20160130,X20160131,X20160201,X20160202,X20160203,X20160204,X20160205,X20160206,X20160207,X20160208,X20160209,X20160210,X20160211 alcoholic_beverages,1,0,0,0,0,3,0,0,2,0,0,1,1,0,0,0,0,1,0,2,0,1 m_active_time,8239,9429,949,1953,6790,8227,6973,12746,7498,4843,5788,9127,2509,5041,8876,3017,4082,8311,6654,941,6725,11963 m_inactive_time,27309,24275,28167,28171,25854,25219,25714,27731,25853,25762,28173,23773,26662,26093,24376,27100,28048,24452,25914,6594,25099,26111 m_lcat,1195,1947,380,882,1264,2132,1198,1887,884,1705,1381,1070,314,944,1760,501,943,1889,1382,437,700,1377 m_steps,14422,16173,2207,3444,11700,14067,11931,13641,13275,8583,10840,16100,4299,9066,16724,5549,7468,14896,11798,1871,10972,11606 m_steps_3am,27,92,0,16,41,0,104,45,2601,47,1557,146,66,11,0,17,36,10,63,65,0,0 m_total_calories_spent,2451.104807,2559.086301,1829.067794,1878.049287,2315.03078,2452.012273,2279.993766,2841.97526,2399.956753,2140.938246,2293.919739,2522.901232,1968.882725,2174.864218,2634.845712,2030.827205,2151.808698,2522.790191,2377.771684,1810.753177,1717.73467,2810.716164 s_asleep_time,899,9337,7399,1811,4359,-443,1750,3506,9772,4684,5420,3165,2582,6016,2608,1367,566,4574,7531,8348,4328,6788 s_awake,1434,1294,783,5041,6816,1234,1441,908,600,2994,7869,441,1535,2617,2831,4028,2049,1198,1001,783,9922,1000 s_awake_time,25107,27231,36436,32257,23282,25110,25194,25095,32520,41467,41730,25829,28434,28126,26198,32181,27104,37336,26625,31083,4277,25200 s_awakenings,2,0,0,2,1,1,2,0,0,2,5,0,1,2,2,3,1,0,0,0,0,0 s_bedtime,599,8737,6799,1211,1841,-1043,1150,2906,9172,4084,4820,2724,1982,5416,2008,639,-34,3974,6931,7748,8255,1100 s_deep,7981,3596,10309,6301,6670,11858,8676,4329,7888,13315,7959,7968,9475,8629,7151,12367,7474,14853,6703,6379,8600,9820 s_duration,23074,17894,29037,26005,14749,24919,22689,21589,22748,34415,29041,22664,25445,20498,22268,27760,25940,32762,19094,22735,22837,25200 s_light,15093,14298,18728,19704,8079,13061,14013,17260,14860,21100,21082,14696,15970,11869,15117,15393,18466,17909,12391,16356,18558,12778 \ No newline at end of file +variables,X20160121,X20160122,X20160123,X20160124,X20160125,X20160126,X20160127,X20160128,X20160129,X20160130,X20160131,X20160201,X20160202,X20160203,X20160204,X20160205,X20160206,X20160207,X20160208,X20160209,X20160210,X20160211 +alcoholic_beverages,1,0,0,0,0,3,0,0,2,0,0,1,1,0,0,0,0,1,0,2,0,1 +m_active_time,8239,9429,949,1953,6790,8227,6973,12746,7498,4843,5788,9127,2509,5041,8876,3017,4082,8311,6654,941,6725,11963 +m_inactive_time,27309,24275,28167,28171,25854,25219,25714,27731,25853,25762,28173,23773,26662,26093,24376,27100,28048,24452,25914,6594,25099,26111 +m_lcat,1195,1947,380,882,1264,2132,1198,1887,884,1705,1381,1070,314,944,1760,501,943,1889,1382,437,700,1377 +m_steps,14422,16173,2207,3444,11700,14067,11931,13641,13275,8583,10840,16100,4299,9066,16724,5549,7468,14896,11798,1871,10972,11606 +m_steps_3am,27,92,0,16,41,0,104,45,2601,47,1557,146,66,11,0,17,36,10,63,65,0,0 +m_total_calories_spent,2451.104807,2559.086301,1829.067794,1878.049287,2315.03078,2452.012273,2279.993766,2841.97526,2399.956753,2140.938246,2293.919739,2522.901232,1968.882725,2174.864218,2634.845712,2030.827205,2151.808698,2522.790191,2377.771684,1810.753177,1717.73467,2810.716164 +s_asleep_time,899,9337,7399,1811,4359,-443,1750,3506,9772,4684,5420,3165,2582,6016,2608,1367,566,4574,7531,8348,4328,6788 +s_awake,1434,1294,783,5041,6816,1234,1441,908,600,2994,7869,441,1535,2617,2831,4028,2049,1198,1001,783,9922,1000 +s_awake_time,25107,27231,36436,32257,23282,25110,25194,25095,32520,41467,41730,25829,28434,28126,26198,32181,27104,37336,26625,31083,4277,25200 +s_awakenings,2,0,0,2,1,1,2,0,0,2,5,0,1,2,2,3,1,0,0,0,0,0 +s_bedtime,599,8737,6799,1211,1841,-1043,1150,2906,9172,4084,4820,2724,1982,5416,2008,639,-34,3974,6931,7748,8255,1100 +s_deep,7981,3596,10309,6301,6670,11858,8676,4329,7888,13315,7959,7968,9475,8629,7151,12367,7474,14853,6703,6379,8600,9820 +s_duration,23074,17894,29037,26005,14749,24919,22689,21589,22748,34415,29041,22664,25445,20498,22268,27760,25940,32762,19094,22735,22837,25200 +s_light,15093,14298,18728,19704,8079,13061,14013,17260,14860,21100,21082,14696,15970,11869,15117,15393,18466,17909,12391,16356,18558,12778 \ No newline at end of file