Presentation on demonstrating function "xtabs" in R
Ashu Guru
Author
03/07/2019
Added
487
Plays
Description
Presentation on demonstrating function "xtabs" in R
Searchable Transcript
Toggle between list and paragraph view.
- [00:00:00.160]So suppose we have data in a CSV file which looks like what we have on the
- [00:00:06.013]screen.
- [00:00:06.880]The first row shows the column headers and then subsequently the rest of the 9
- [00:00:14.140]rows have the data and what we want to do is we want to read it in R and let R
- [00:00:21.401]create a frequency table of number of entries per block.
- [00:00:26.800]So what we want to do is we want to create a frequency table like this.
- [00:00:34.800]So it basically says in block number one, the entry 3 has no representation,
- [00:00:48.336]entry 8 is present once, 24 is not in block 131 is not in block 1
- [00:00:59.938]and then 45 is in block 1 and the 45 is in block 1.
- [00:01:09.360]So similarly we want to basically create a table of frequency of entries per block.
- [00:01:16.680]We want R to actually calculate and create this frequency table for us and to
- [00:01:23.656]do this it's a very simple task in R and it's done using a function called X tabs.
- [00:01:31.480]So I am going to in my R studio now read the files.
- [00:01:37.840]The first step is I'm going to change my working directory to the folder where I
- [00:01:43.702]have my CSV file and that is done by set WD.
- [00:01:48.400]Next, I'm going to read the file in a in a
- [00:01:51.394]variable called field data table and that is done by read table.
- [00:01:56.240]The file name and my header is true separators, Let's ignore this typo.
- [00:02:07.600]Next I'm going to print the structure of the variable.
- [00:02:11.640]This is the structure of the variable field data table for R and now we simply
- [00:02:21.049]run X tab and we have a squiggly character and this is the character above
- [00:02:29.982]the tab on your keyboard.
- [00:02:33.440]And then we say entry per block.
- [00:02:39.160]It's represented by a + and the variable that we want.
- [00:02:43.960]So the entry variable comes from field data table and block variable comes from
- [00:02:48.950]field data table and the output is what we would had expected.
The screen size you are trying to search captions on is too small!
You can always jump over to MediaHub and check it out there.
Log in to post comments
Embed
Copy the following code into your page
HTML
<div style="padding-top: 56.25%; overflow: hidden; position:relative; -webkit-box-flex: 1; flex-grow: 1;"> <iframe style="bottom: 0; left: 0; position: absolute; right: 0; top: 0; border: 0; height: 100%; width: 100%;" src="https://mediahub.unl.edu/media/10751?format=iframe&autoplay=0" title="Video Player: Presentation on demonstrating function "xtabs" in R" allowfullscreen ></iframe> </div>
Comments
0 Comments