From the course: R for Data Science: Lunch Break Lessons

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Use setnames() to change the name of an object

Use setnames() to change the name of an object

From the course: R for Data Science: Lunch Break Lessons

Use setnames() to change the name of an object

- [Instructor] SetNames is a confusing function that sets the name of an object and returns the object. Let me show you how it works, explain the confusion, explain an alternative, and then show you how to actually use it. So to demonstrate setNames, I need a vector. And we'll create one called thisVector. And then I also need a vector of vector names to name that vector. So I've created a second vector called vectorNames. Now, let's use setNames to set the name of each thisVector element to the name of vectorNames. First, we'll let's take a look at the raw thisVector. And you can see that it's just the three names that are in the vector, bibbity, bobbity, and boo. Now if I use setNames, thisVector, and I name the elements in thisVector with vectorNames, you'll see that I now have the original three elements of thisVector, bibbity, bobbity, boo, along with the names of each element in the vector. So across the top…

Contents