 It's LinkedIn Learning author Monica Wahee with today's data science makeover. Watch while Monica Wahee demonstrates how to use the paste command to create labels from data in R. Hi everyone. If you are feeling like this is deja vu, it's not. I actually have another video on how to do the paste command in R. Only that video demonstrates the command without any underlying data set. I'll link you to that video in the description. But that's not any fun making a label without an underlying data set. That's easy. Let's do something hard. So we are going to use paste again, but this time we are going to involve an underlying data set. This data set I made called line items. It's in RDS format and we are going to read it in. If you need help reading RDS files into R, don't worry. Just look for the link to my video on how to do that in the description. Okay, so let's start by reading in this data set called line items, and then I'm going to run the data set so we can see it in the console and look at the data. Okay, this is kind of a long data set, but let's get to the top. See this last variable called tot underscore cost? Pretend that stands for total cost. So you can see there are costs in this variable. They look like they are all around $50 or $100 or $200. So this is the variable we are going to use in our paste command demonstration today. Let's go back to our code. Okay, let's say we are building a report in R or a plot in R or a report that will have a plot in R. And let's say that in this report with a plot, we want to emphasize the maximum value of this variable tot underscore cost or total cost. In other words, we want to call attention to the highest value of total cost, meaning the most expensive thing, right? See this max command? I'm running the max command on the variable tot underscore cost in the data frame named line items. I'm just doing that so I am informed about what value I'm expecting to show up in my paste label. Let's run this and inform ourselves. We'll look at that. The maximum tot underscore cost is $293.88. That's almost $300, but not quite. So that's the number we want to include in our report label or our plot label or both if we do both. Let's go back to our code. See this? This is the line of code that makes our new label with the max tot underscore cost in it. I'm saving the pasted string as an object named report underscore label. See the little arrow? If I didn't do that and I just ran the paste command to the screen, it would print out to the console. But then I would have it saved as an object that I could later call up on a report or a plot. So I have to save it as this object called report underscore label. Okay, this is a little hard to see, but this paste command has three arguments plus the sep argument at the end. Notice the sep argument is just two quotes next to each other without anything in between them. No spaces, no dashes, no nothing. That means that when R paste the string into the object report underscore label, it is supposed to put the three arguments before the sep argument right next to each other and not separate them within a space. Because of that, you can see why I formatted each argument the way I did. The first argument is this character string enclosed in quotes that says the maximum total cost is. Now, notice that after the is, I put a space before I put the closed quote. That's because my sep option is going to smash the next argument right up next to this one. So I have to build in the space or else the value will be in the personal space of the is and we won't want that. Okay, next we have our max command, the one we ran above. We know what that will say, which is 293.88. Of course, we could hard code that, but we are theoretically pretending that the underlying data changes, like in a dashboard where someone is updating these line items and the maximum total cost keeps changing. So this way, by using a max calculation, we are making our data label be flexible. So that's the second argument. And then the last argument in the string is just this character string with exclamation points. And finally, we end it with the sep argument. All right, first, I'll run this whole line of code. And then I'll run the report underscore label object. So we can look at how it came out. Okay, no surprises. The maximum total cost is 293.88 exclamation point exclamation point exclamation point exclamation point. I guess I could have included a dollar sign in there. Maybe I'll do that next time. Otherwise, this looks pretty cute, doesn't it? Too cute by half, I'd say. Thank you for watching this data science makeover with LinkedIn Learning author Monica Wahee. Remember to check out Monica's data science courses on LinkedIn Learning. Click on the link in the description.