[R] Regroup and create new dataframe
nguy2952 University of Minnesota
nguy2952 @ending from umn@edu
Fri Jun 1 17:54:03 CEST 2018
Hello folks,
I have a big project to work on and the dataset is classified so I am just
going to use my own example so everyone can understand what I am targeting.
Let's take Target as an example: We consider three brands of tape: Target
brand, 3M and Avery. The original data frame has 4 columns: Year of Record,
Product_Name(which contains three brands of tape), Sales, and Region. I
want to create a new data frame that looks like this:
Year of Record Sales Region
Target Brand
3M
Avery
Here is what I did.
1.
I split the original data frame which I called data1:
X = split(data1, Product_name)
2.
Unlist X
X1 = unlist(X)
3.
Create a new data frame
new_df = as.data.frame(X1)
But, when I used the command View(new_df), I had only two columns: The left
one is similar to TargetBrand.Sales, etc. and the right one is just "X1"
I did not achieve what I wanted.
**A potentially big question from readers:*
Why am I doing this?
*Answer:*
I want to run a multiple regression model later to see among different
regions, what the sales look like for these three brands of tape:
*Does Mid-west buy more house brand than East Coast?*
or
*Does region really affect the sales? Are Mid-West's purchases similar to
those of East Coast and West Coast?*
I need help. Please give me guidance.
Sincerely,
Hugh N
[[alternative HTML version deleted]]
More information about the R-help
mailing list