Presentation on demonstrating function "str" in R
Ashu Guru
Author
03/07/2019
Added
547
Plays
Description
Presentation on demonstrating function "str" in R.
Searchable Transcript
Toggle between list and paragraph view.
- [00:00:00.760]So let's take a look at the STR function in R.
- [00:00:04.320]And suppose we have data that is stored in a CSV file,
- [00:00:08.160]and the data looks something like this.
- [00:00:10.400]So let me show you the actual file first.
- [00:00:14.600]So this is the data file we have.
- [00:00:16.720]So we have first row, which gives the name of the columns--
- [00:00:20.800]plot, entry, name, block, and TSW.
- [00:00:23.400]And the subsequent rows give the values
- [00:00:26.040]for that particular column.
- [00:00:29.880]So this is the data that we have in a file.
- [00:00:32.920]And what we want to do is we want
- [00:00:34.340]to read this data in a table variable in R.
- [00:00:40.280]We would like R to tell us the structure of the variable
- [00:00:47.200]and, in some sense, how was the data actually
- [00:00:50.900]stored in that text file.
- [00:00:53.140]So for this particular case where the data file is small,
- [00:00:57.560]you may question that why do we even need
- [00:00:59.760]a function like this.
- [00:01:00.760]But when the file size is larger,
- [00:01:03.360]STR function is very handy to quickly see
- [00:01:06.200]when I read this file in an R variable, what
- [00:01:09.580]is the structure of that data.
- [00:01:11.800]So let's take a look.
- [00:01:14.440]As always, I'm going to set the working directory of my R
- [00:01:19.000]environment to the folder where I have the file.
- [00:01:22.880]And setwd does that.
- [00:01:25.660]And then I'm going to load the data in
- [00:01:29.640]the variable and the command to do that is read.table.
- [00:01:36.090]so I'm gonna run the command field table and now let's see the output of the STR
- [00:01:46.470]command. So once we run STR on the variable that we read the file into we
- [00:01:55.350]see that R tells us that there are nine observations of five variables so
- [00:02:00.650]let's bring back our Excel, the CSV file.
- [00:02:06.690]And we have nine rows so it has nine observations and five variables one, two,
- [00:02:18.430]three, four, five and it also tells us that plot is an integer value so plot is
- [00:02:24.670]having an integer value and the first few values are starting 101,
- [00:02:30.650]102, 103 which is correct. It also tells us that
- [00:02:37.010]the entry thus the second variable is entry and it is an integer type and
- [00:02:44.750]values are eight forty five ninety. Similarly name is a factor type which
- [00:02:53.750]with eight levels so R was able to find out that name is a factor type because
- [00:03:00.650]there were a few values which were character strings and then block is
- [00:03:06.910]again an integer value and TSW is a number value.
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/10749?format=iframe&autoplay=0" title="Video Player: Presentation on demonstrating function "str" in R" allowfullscreen ></iframe> </div>
Comments
0 Comments