Power BI is described in this video as a feature-rich business intelligence application that includes capabilities for data transformation, acquisition, and visualization. But many people find it difficult to grasp Power BI; however, R users can shorten the learning curve by using Tidyverse. This presentation introduces viewers to Tidyverse and shows them how to use it to quickly learn Power BI and do tasks that may not be achievable with Power BI’s built-in capability.
—-This video is not about replacing R Studio with Power BI.—-
(b) Differeneces between R and Pyhton
1.Assignment Operator
In R programming language, <- is used for assignment operation which I had a hard time getting used to. <- is used for creating variable and assigning a values. However,to do assignment operation, we use the “=” symbol, which Prof. Daşdemir finds more logical in the R programming language. One of the main differences between two programming language is assignment operator.
Here an example of usage of <- for assignment operation in R :
# Assign the value of 7 which is my lucky number to the variable 'my_lucky_number'my_lucky_number <-7#Update the value of 'my_lucky_number'my_lucky_number <- my_lucky_number +2# Print the new value of variable 'my_lucky_number'print(my_lucky_number)
[1] 9
Here an example of usage of <- for assignment operation in Python:
# Assign the value of 7 to the variable 'my_lucky_number'my_lucky_number =7#Update the value of 'my_lucky_number'my_lucky_number +=2# Print the new value of variable 'my_lucky_number'print(my_lucky_number)
9
2. Mean Function
The majority of functions are built into the R programming language, making it easier to use; but, in order to utilize them in Python, we must download libararies. For example, ‘mean’;
Here an example of usage of mean function in R :
heights_in_cm <-c(185,190, 178, 192, 188, 176, 180)average <-mean(heights_in_cm)cat("the average of heights:", average)
the average of heights: 184.1429
Here an example of usage of mean function in Pyhton :
# Import numpy for using mean functionimport numpy as npheights_in_cm = [185, 190, 178, 192, 188, 176, 180]#Calculate of average of heightsaverage = np.mean(heights_in_cm)# Print the value of variableprint("the average of heights:", average)
the average of heights: 184.14285714285714
3. Calculating the Square Roots of Elements in List
While we perform the square root calculations of the elements in a list by looping over a list in Python, we perform the same operation using the sqrt function in R.
Here an example of calculating square root in R:
vector <-c(25, 36, 121,9)#Calculate square roots of elementssquare_roots <-sqrt(vector)#Print the list of square rootscat("square_roots:", square_roots)
square_roots: 5 6 11 3
Here an example of calculating square root in Python :
list= [25, 36, 121,9] square_roots = []#Calculate square roots and add the list of themfor i inlist: square_roots.append(i**0.5)#Print the list of square rootsprint("square_roots:", square_roots)
square_roots: [5.0, 6.0, 11.0, 3.0]
(c) na_example Data Set
In this section, we examine the na_example data set to identify NAs and replace them with 0.
# Import the “na_example” data setlibrary(dslabs)data("na_example")#Print the data set na_example
[1] 2 1 3 2 1 3 1 4 3 2 2 NA 2 2 1 4 NA 1 1 2 1 2 2 1
[25] 2 5 NA 2 2 3 1 2 4 1 1 1 4 5 2 3 4 1 2 4 1 1 2 1
[49] 5 NA NA NA 1 1 5 1 3 1 NA 4 4 7 3 2 NA NA 1 NA 4 1 2 2
[73] 3 2 1 2 2 4 3 4 2 3 1 3 2 1 1 1 3 1 NA 3 1 2 2 1
[97] 2 2 1 1 4 1 1 2 3 3 2 2 3 3 3 4 1 1 1 2 NA 4 3 4
[121] 3 1 2 1 NA NA NA NA 1 5 1 2 1 3 5 3 2 2 NA NA NA NA 3 5
[145] 3 1 1 4 2 4 3 3 NA 2 3 2 6 NA 1 1 2 2 1 3 1 1 5 NA
[169] NA 2 4 NA 2 5 1 4 3 3 NA 4 3 1 4 1 1 3 1 1 NA NA 3 5
[193] 2 2 2 3 1 2 2 3 2 1 NA 2 NA 1 NA NA 2 1 1 NA 3 NA 1 2
[217] 2 1 3 2 2 1 1 2 3 1 1 1 4 3 4 2 2 1 4 1 NA 5 1 4
[241] NA 3 NA NA 1 1 5 2 3 3 2 4 NA 3 2 5 NA 2 3 4 6 2 2 2
[265] NA 2 NA 2 NA 3 3 2 2 4 3 1 4 2 NA 2 4 NA 6 2 3 1 NA 2
[289] 2 NA 1 1 3 2 3 3 1 NA 1 4 2 1 1 3 2 1 2 3 1 NA 2 3
[313] 3 2 1 2 3 5 5 1 2 3 3 1 NA NA 1 2 4 NA 2 1 1 1 3 2
[337] 1 1 3 4 NA 1 2 1 1 3 3 NA 1 1 3 5 3 2 3 4 1 4 3 1
[361] NA 2 1 2 2 1 2 2 6 1 2 4 5 NA 3 4 2 1 1 4 2 1 1 1
[385]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3 2 NA 2 1
[841] 4 2 NA NA NA 2 4 2 NA NA 3 1 NA 5 5 2 2 2 NA 2 1 3 1 3
[865] 2 4 2 4 NA 4 1 2 3 2 3 3 2 3 2 2 2 1 3 2 4 2 NA 3
[889] 3 2 2 NA NA 3 2 1 2 4 1 1 1 1 4 3 2 NA 3 2 NA 1 NA 3
[913] 2 1 1 1 2 NA 2 2 3 3 2 NA NA 4 5 2 2 2 1 2 3 1 3 3
[937] 4 3 NA 1 1 1 NA 4 3 5 1 1 2 NA 2 2 2 2 5 2 2 3 1 2
[961] 3 NA 1 2 NA NA 2 NA 3 1 1 2 5 3 5 1 1 4 NA 2 1 3 1 1
[985] 2 4 3 3 3 NA 1 1 2 2 1 1 2 2 NA 2
# Count the total number of NAtotal_number_NA1 <-sum(is.na(na_example))cat("TOTAL NUMBER OF NA :", total_number_NA1 )
TOTAL NUMBER OF NA : 145
# Create new variable for data set with 0na_example_with_0 <- na_example# Replace NAs with 0na_example_with_0[is.na(na_example)] <-0# Print new data set with 0na_example_with_0