I'm still a novice to R. Can anyone help me figure out how to spread my dataset under different categories?
Here is what I got in R.
Values with "item code" fall in "broad category", others are in the subcategories (actual items). So now, I wanna separate values in subcategories (that is, values with NA
code) and make it into the third column ((Like column#1 is "Item Code", column#2 is "Broad category", and column #3 is " Specific items")
More specifically, I wish the final result just look like this:
I'm thinking about using the spread()
command, but it seems it doesn't work. Could anyone give me some suggestions on my following steps?
(I'm thinking about specifying "broad categories" as a variable, and "subcategories" as another variable, and then, I might be able to spread the table? Not sure)