I can use mutate to update my existing variable: mutate(cats, weight = round(weight, 2)) # street coat sex age weight fixed wander_dist Let’s say I don’t want a lot of decimal places in one of my measurements. mutate allows us to do this relatively easily. One common task in working with data is updating/cleaning some of the values in columns. # 10 no 234 # you can include additional columns to help sort the dataĪrrange(cats, coat, sex) # street coat sex age weight fixed wander_dist arrange(cats, coat) # street coat sex age weight fixed wander_dist arrange allows us to change the order of rows in our dataset based on their values. Maybe you have a set of observations in your data that you want to organize by their value. We can select more columns by giving select additional arguments, and our output ame will have columns according to the order of our arguments select(cats, coat, cat_id) # coat cat_id All of the main “verbs” we’ll talk about will return a ame as their result. Notice how the output differs slightly all the main dplyr verbs behave consistently in that their inputs and outputs are both ames, rather than returning a simple vector as the bracket-indexing method did. With dplyr, we don’t need to enclose our column names in quotes select(cats, coat) # coat # Levels: black brown calico maltese tabby Let’s use our cats dataset and select only the coat column we did this previously with cats # tabby maltese brown black calico tabby brown brown The first command we’ll use is select, which allows us to choose columns from our dataset.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |