Message-ID: <33f7b044-3803-48d1-2931-f087f8ed9730@sapo.pt>
Date: 2018-05-26T13:22:59Z
From: Rui Barradas
Subject: Grouping by 3 variable and renaming groups
In-Reply-To: <000201d3f4f1$ec25c3f0$c4714bd0$@sbcglobal.net>
Hello,
See if this is it:
priceStore_Grps$StoreID <- paste("Store",
seq_len(nrow(priceStore_Grps)), sep = "_")
Hope this helps,
Rui Barradas
On 5/26/2018 2:03 PM, Jeff Reichman wrote:
> ALCON
>
>
>
> I'm trying to figure out how to rename groups in a data frame after groups
> by selected variabels. I am using the dplyr library to group my data by 3
> variables as follows
>
>
>
> # group by lat (StoreX)/long (StoreY)
>
> priceStore <- LapTopSales[,c(4,5,15,16)]
>
> priceStore <- priceStore[complete.cases(priceStore), ] # keep only non NA
> records
>
> priceStore_Grps <- priceStore %>%
>
> group_by(StorePC, StoreX, StoreY) %>%
>
> summarize(meanPrice=(mean(RetailPrice)))
>
>
>
> which results in .
>
>
>
>> priceStore_Grps
>
> # A tibble: 15 x 4
>
> # Groups: StorePC, StoreX [?]
>
> StorePC StoreX StoreY meanPrice
>
> <fct> <int> <int> <dbl>
>
> 1 CR7 8LE 532714 168302 472.
>
> 2 E2 0RY 535652 182961 520.
>
> 3 E7 8NW 541428 184515 467.
>
> 4 KT2 5AU 517917 170243 522.
>
> 5 N17 6QA 533788 189994 523.
>
>
>
> Which is fine, but I then want to give each group (e.g. CR7 8LE 532714
> 168302) a unique identifier (say) Store 1, 2, 3 or some other unique
> identifier.
>
>
>
> StorePC StoreX StoreY meanPrice
>
> <fct> <int> <int> <dbl>
>
> 1 CR7 8LE 532714 168302 472. Store 1
>
> 2 E2 0RY 535652 182961 520. Store 2
>
> 3 E7 8NW 541428 184515 467. Store 3
>
> 4 KT2 5AU 517917 170243 522. Store 4
>
> 5 N17 6QA 533788 189994 523. Store 5
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>