Data Science Initiative Introduction To R Bootcamp (part 2)

Because now I’m just repeating the same code over and over and over and over again and that means that if I ever find an error in us or if I ever want want to make it do something different I’ll probably break everything that went before us or if I find an error I’ll have to change it everywhere so what do we do this is this is a little notch tiny bit up but really not hard okay if you followed along with the code.

Yesterday attempted to compute that and again it was just.

Sub setting and vectorized arithmetic and so forth I just copied this basically in here you’ll see it’s data dollar long I’ve changed data from dated from Davis.

To data okay that’s great that doesn’t matter it’s just.

The main I could have left it at Davis but I didn’t want to I wanted to give it a more generic name but it’s exactly the same code that I copied okay I changed the pointer 1 to B proximity because.

I don’t know it’s always going to be 0.01 okay so I can set that as a variable and then I could just change that in one place it now becomes more symbolic rather than actually hard-coded 0.

A bit more flexible it’s a little bit more flexible then and then we just do this and we do exactly the same computation so almost nothing has changed except for this name this name this value with instead of.

The literal value we put it in as a as a name okay a variable and then the rest of.

It stays the same okay then I just changed then I just this is my code that hasn’t changed much at all and then I just put it inside that says this is a block of code that is a single unit okay and then I say hey here’s a function this is and you see in my in my text editor and in our studio function is a very very special word it’ll get it it’ll get a different color okay for the text it.

Says I’m creating a function just like the plot function and Gen John box plus and filter and all.

Of them the sub operator these are just regular functions in our you can write your own and here’s this is we’re writing us I basically say hey function it takes it takes a data set I need to know the observations that I’m looking through this.

Is great because now it’s not locked in on that one Davis data set it’s actually I can specify different data sets I can subset Davis and hand.

In a smaller subset or I can actually get another day’s worth of data and hand that in here’s the value of proximity you have to tell me how close you want to be but I’m gonna say 0.

Default so you don’t have to tell me and you just say here’s my data go get me the nearest thing within point oh one but if you decide that you’re gonna branch out.02 units okay but that’s that’s up to me or the arts are to you the caller.

Can basically change the value for proximity or just use the default and then you also need to tell me where to start from but you know what let’s just assume it’s shield library okay so we’ll always we’ll just make this function always think it’s shield library but so that’s the I don’t know I’m no idea where this is but the M oh.