{"id":400,"date":"2020-02-22T14:33:53","date_gmt":"2020-02-22T14:33:53","guid":{"rendered":"https:\/\/openlab.bmcc.cuny.edu\/mat-150-introductory-statistics\/?p=400"},"modified":"2020-04-15T21:29:42","modified_gmt":"2020-04-15T21:29:42","slug":"frequency-tables-using-r","status":"publish","type":"post","link":"https:\/\/openlab.bmcc.cuny.edu\/mat-150-introductory-statistics\/2020\/02\/22\/frequency-tables-using-r\/","title":{"rendered":"Frequency Tables Using R Part 1"},"content":{"rendered":"\r\n<h4 class=\"wp-block-heading\">How Do We Construct A Frequency Distribution Table Using R? Part 1<\/h4>\r\n\r\n\r\n\r\n<h5 class=\"wp-block-heading\">We will use <em>States Visited<\/em>, (<em>StatesV<\/em>) variables included in the first-day class survey, <em>Sur1<\/em>.<\/h5>\r\n\r\n\r\n\r\n<ol class=\"wp-block-list\">\r\n<li>Upload Sur1.csv data set from your desktop to R<\/li>\r\n<\/ol>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>Sur1 &lt;-read.csv(\"~\/Desktop\/Sur1.csv\")<\/code><\/pre>\r\n\r\n\r\n\r\n<p>NOTE: In case you did not save <em>Sur1.csv<\/em> file correctly to your desktop, execute the following code<br \/><strong>Sur1 &lt;-read.csv(read.csv(file.choose(),header = TRUE))<\/strong><\/p>\r\n\r\n\r\n\r\n<ol class=\"wp-block-list\">\r\n<li>Examinne the strucure of Sur1 data set<\/li>\r\n<\/ol>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>str(Sur1)<\/code><\/pre>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>## 'data.frame':    20 obs. of  6 variables:\r\n##  $ SEX      : Factor w\/ 2 levels \"Female\",\"Male\": 1 1 1 1 2 2 2 1 1 1 ...\r\n##  $ POLITICS : Factor w\/ 3 levels \"Conservative\",..: 3 3 3 3 3 3 2 2 1 3 ...\r\n##  $ NSiblings: int  4 4 2 2 2 4 5 4 4 1 ...\r\n##  $ StatesV  : int  5 11 6 3 7 3 4 4 6 3 ...\r\n##  $ ShoeS    : num  6 9 8 7.5 13 10.5 9 8 6 8.5 ...\r\n##  $ UsedExcel: int  2 2 2 1 1 3 3 2 2 1 ...<\/code><\/pre>\r\n\r\n\r\n\r\n<ol class=\"wp-block-list\">\r\n<li>View first six row of the data in spreadsheet format<\/li>\r\n<\/ol>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>head(Sur1, 6)<\/code><\/pre>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>##      SEX POLITICS NSiblings StatesV ShoeS UsedExcel\r\n## 1 Female Moderate         4       5   6.0         2\r\n## 2 Female Moderate         4      11   9.0         2\r\n## 3 Female Moderate         2       6   8.0         2\r\n## 4 Female Moderate         2       3   7.5         1\r\n## 5   Male Moderate         2       7  13.0         1\r\n## 6   Male Moderate         4       3  10.5         3<\/code><\/pre>\r\n\r\n\r\n\r\n<ol class=\"wp-block-list\">\r\n<li>Attach Sur1 to R in order to work with data variables without using <strong>$<\/strong> symbol (remember to detach(Sur1) after completion of analysis)<\/li>\r\n<\/ol>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>attach(Sur1)<\/code><\/pre>\r\n\r\n\r\n\r\n<ol class=\"wp-block-list\">\r\n<li>Summarize <em>StatesV<\/em> variable<\/li>\r\n<\/ol>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>summary(StatesV)<\/code><\/pre>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. \r\n##    3.00    4.00    6.00    7.15    9.50   18.00<\/code><\/pre>\r\n\r\n\r\n\r\n<ol class=\"wp-block-list\">\r\n<li>Construct a frequency distribution table of <em>States Visited<\/em> using breaks to list class limits<\/li>\r\n<\/ol>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>breaks &lt;-seq(0,18, by=3)<\/code><\/pre>\r\n\r\n\r\n\r\n<ol class=\"wp-block-list\">\r\n<li>Group <em>StatesV<\/em> variable data into bins<\/li>\r\n<\/ol>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>StatesV.cut &lt;-cut(StatesV,breaks)<\/code><\/pre>\r\n\r\n\r\n\r\n<ol class=\"wp-block-list\">\r\n<li>Construct frequency table for <em>StatesV<\/em> variable in horizontal display<\/li>\r\n<\/ol>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code> table(StatesV.cut)<\/code><\/pre>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>## StatesV.cut\r\n##   (0,3]   (3,6]   (6,9]  (9,12] (12,15] (15,18] \r\n##       3       8       4       3       1       1<\/code><\/pre>\r\n\r\n\r\n\r\n<ol class=\"wp-block-list\">\r\n<li>Transform this table to 2-column display<\/li>\r\n<\/ol>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>transform(table(StatesV.cut))<\/code><\/pre>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>##   StatesV.cut Freq\r\n## 1       (0,3]    3\r\n## 2       (3,6]    8\r\n## 3       (6,9]    4\r\n## 4      (9,12]    3\r\n## 5     (12,15]    1\r\n## 6     (15,18]    1<\/code><\/pre>\r\n\r\n\r\n\r\n<ol class=\"wp-block-list\">\r\n<li>Construct a histogram of the frequency distribution of <em>StatesV<\/em> variable<\/li>\r\n<\/ol>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>hist(StatesV,breaks,col=\"red\",border = \"blue\",xlab=\"Number of States Visited\",xlim = c(0,21),ylab=\"Frequency\",main=\"Distribution of States Visited by Mat150-1701 Students\")<\/code><\/pre>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"731\" class=\"wp-image-401\" src=\"https:\/\/openlab.bmcc.cuny.edu\/mat-150-introductory-statistics\/wp-content\/uploads\/sites\/110\/2020\/02\/image-1024x731.png\" alt=\"\" srcset=\"https:\/\/openlab.bmcc.cuny.edu\/mat-150-introductory-statistics\/wp-content\/uploads\/sites\/110\/2020\/02\/image-1024x731.png 1024w, https:\/\/openlab.bmcc.cuny.edu\/mat-150-introductory-statistics\/wp-content\/uploads\/sites\/110\/2020\/02\/image-300x214.png 300w, https:\/\/openlab.bmcc.cuny.edu\/mat-150-introductory-statistics\/wp-content\/uploads\/sites\/110\/2020\/02\/image-768x549.png 768w, https:\/\/openlab.bmcc.cuny.edu\/mat-150-introductory-statistics\/wp-content\/uploads\/sites\/110\/2020\/02\/image.png 1344w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\r\n","protected":false},"excerpt":{"rendered":"<p>How Do We Construct A Frequency Distribution Table Using R? Part 1 We will use States Visited, (StatesV) variables included in the first-day class survey, Sur1. Upload Sur1.csv data set from your desktop to R NOTE: In case you did not save Sur1.csv file correctly to your desktop, execute the following codeSur1 &lt;-read.csv(read.csv(file.choose(),header = TRUE)) [&hellip;]<\/p>\n","protected":false},"author":142,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"portfolio_post_id":0,"portfolio_citation":"","portfolio_annotation":"","openlab_post_visibility":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-400","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mat-150-introductory-statistics\/wp-json\/wp\/v2\/posts\/400","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mat-150-introductory-statistics\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mat-150-introductory-statistics\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/openlab.bmcc.cuny.edu\/mat-150-introductory-statistics\/wp-json\/wp\/v2\/users\/142"}],"replies":[{"embeddable":true,"href":"https:\/\/openlab.bmcc.cuny.edu\/mat-150-introductory-statistics\/wp-json\/wp\/v2\/comments?post=400"}],"version-history":[{"count":4,"href":"https:\/\/openlab.bmcc.cuny.edu\/mat-150-introductory-statistics\/wp-json\/wp\/v2\/posts\/400\/revisions"}],"predecessor-version":[{"id":626,"href":"https:\/\/openlab.bmcc.cuny.edu\/mat-150-introductory-statistics\/wp-json\/wp\/v2\/posts\/400\/revisions\/626"}],"wp:attachment":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mat-150-introductory-statistics\/wp-json\/wp\/v2\/media?parent=400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openlab.bmcc.cuny.edu\/mat-150-introductory-statistics\/wp-json\/wp\/v2\/categories?post=400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openlab.bmcc.cuny.edu\/mat-150-introductory-statistics\/wp-json\/wp\/v2\/tags?post=400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}