Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Betty888
Helper II
Helper II

R in Power suery : How to extend my code that works by group to all data

Dear all,
I'm trying to analyse the effect of "Factor1" and "Factor2" on the response variable "perf" by "location", and obtaining at the end my original dataset associated to the lsmeans and tukey groups letters. Here below the code I'm using that gives me exactly what I need but only by location, my need is : how can I extend it in a way my output combines results of all locations, i.e, output of lsmeans and CLD by location :

library(multcomp)
library(lsmeans)
library(dplyr)
library(broom)

output <- as.data.frame(dataset)
output$perf <- as.numeric(output$perf)
output$factor1 <- as.factor(output$factor1)
output$factor2 <- as.factor(output$factor2)
output <- output %>% 
           group_by(location) %>% 
           mutate(row=row_number()) 

model <- lm(perf ~ factor1 + factor2, data = output)
lsmeans <- lsmeans(model, ~ factor1)
CLD = cld(lsmeans,
            alpha   = 0.05,
            Letters = letters,
            adjust  = "tukey")         

output <- left_join(output, CLD, by = "factor1")
Thank you in advance for your help !
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Betty888 

You can consider to create a new column instead of group_by, you can refer to the following link, it may help you.

Concatenating strings with multiple separators using paste() in R - Stack Overflow

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Betty888 

You can consider to create a new column instead of group_by, you can refer to the following link, it may help you.

Concatenating strings with multiple separators using paste() in R - Stack Overflow

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Many thanks ! 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors