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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Cortana
Helper III
Helper III

Same R scripts but different result on Power BI

I was trying to draw a correlation plot in powerBI using R scripts. But it is showing different results. 

Here is my R scripts code- 

 

library(corrplot)
A = cor(na.omit(dataset))
corrplot(A, method = "number", col="black")

 

output from R is like the below picture-

Rplot.png

  

And the output from PBI is like the below picture-

Capture.PNG

 

Same dataset, but the values are not equal. Is there anything I missed?

7 REPLIES 7
lbendlin
Super User
Super User

Not necessarily.  Note this comment in the Power BI code window:

 

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script: 

# dataset <- data.frame(A, B, C, D, E, F, G, H, I)
# dataset <- unique(dataset)

Unless you also drop the index column and remove duplicates in your standard R script  you are likely to get different results.

 

took me a couple tries but here you can see it gets the same result.

 

lbendlin_0-1662464081521.png

 

I know. But it still does not give me the same result.

Have you tried my version of the R code?

lbendlin
Super User
Super User

would you mind providing the sample data?

@lbendlin 

As the data size is too big I was trying to share some sample data. But later I found that a small amount of data matched perfectly but the real data does not. Here you will get the real data. The size is about 70MB.. 

Your implementation of na.omit may lead to unintended side effects. As you specify it this will remove all rows where any of the columns is "NA" 

 

Here is my result based on the data you provided. It has 3285939 rows but only 3117 rows will be left after the na.omit().

lbendlin_0-1662396120012.png

 

 

 

Yeah. It removes maximum rows, but my question is if I run the script in R and PBI separately, it gives me a different result. Shouldn't it be same?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.