课程: R for Data Science: Lunch Break Lessons

免费学习该课程!

今天就开通帐号,24,100 门业界名师课程任您挑!

Change the structure of a vector with stack()

Change the structure of a vector with stack()

- [Instructor] The R language command stack, provides a way to change the structure between names and qualities in a data frame or a list. Now that's a little bit confusing. So let's look at an example. In this example I've created my data frame and my data frame is three observations of two variables. Let's take a look at it real quick. My data frame. You can see that the first column is labeled fruit and that column contains orange, banana and mango. The second column or variable contains qualities of that particular fruit. So in the first line the qualities of an orange are orange and vitamin C, a banana is yellow and has potassium and a mango is green. And um, anyhow, let's look at stack. What happens if I take my data frame and you stack on it, you'll immediately note that my data frame has been rotated 90 degrees in that the values of the first column are now orange, banana, mango and then orange, vitamin C,…

内容