Displaying 3 results from an estimated 3 matches for "storepc".
2018 May 26
3
Grouping by 3 variable and renaming groups
...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 4...
2018 May 26
0
Grouping by 3 variable and renaming groups
...llows
>
>
>
> # 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
>
>...
2018 May 26
1
Grouping by 3 variable and renaming groups
Hello,
Sorry, but I think my first answer is wrong.
You probably want something along the lines of
sp <- split(priceStore_Grps, priceStore_Grps$StorePC)
res <- lapply(seq_along(sp), function(i){
sp[[i]]$StoreID <- paste("Store", i, sep = "_")
sp[[i]]
})
res <- do.call(rbind, res)
row.names(res) <- NULL
Hope this helps,
Rui Barradas
On 5/26/2018 2:22 PM, Rui Barradas wrote:
> Hello,
>
> See if...