Differentiate Between Categorical and Numerical Independent Variables in R

Nizamuddin Siddiqui
Updated on 03-Nov-2021 08:02:54

837 Views

For categorical variable, each level is considered as an independent variable and is recognized by factor function. On the other hand, the numerical independent variable is either continuous or discrete in nature.Check out the Example given below for linear regression model summary to understand the difference between categorical and numerical independent variables.ExampleFollowing snippet creates a sample data frame −x

Reverse and Add Function in Java

Sunidhi Bansal
Updated on 03-Nov-2021 08:02:33

688 Views

We are given with an integer and the agenda here is to reverse the digits of the number and add the reversed number to the original number and check if the resultant number is a palindrome or not and the process is repeated until it does. The breaking point of the process is 1000 iterations and a value greater than the maximum long value( Long.MAX_VALUE).For ExamplesInput − 1678Output − Palindrome of the given input 1678 293392Explanation − The input number is first reversed and then added to the original number, it is then checked for palindrome if it is not a palindrome ... Read More

Create Upper Triangular Matrix Using Vector Elements in R

Nizamuddin Siddiqui
Updated on 03-Nov-2021 08:02:11

3K+ Views

To create an upper triangular matrix using vector elements, we can first create the matrix with appropriate number of columns and rows then take the transpose of that matrix. After that we will assign the lower triangular matrix elements to 0.The selection of number of rows and columns plays an important role here so we need to be careful while choosing them.Check out the examples given below to understand how it can be done.Example 1Following snippet creates a vector −x1

Reverse Actual Bits of a Given Number in Java

Sunidhi Bansal
Updated on 03-Nov-2021 07:58:16

1K+ Views

Given an integer n that is not negative. The goal is to reverse the bits of n and report the number that results from doing so. While reversing the bits, the actual binary form of the integer is used; no leading 0s are taken into account.Let us see various input output scenarios for thisInput − 13Output − Reverse actual bits of the given number 11(13)10 = (1101)2. After reversing the bits, we get: (1011)2 = (11)10.Explanation − The binary bits are obtained from the input number which is then reversed and finally converted to decimal format which is returned as output.Input − 18Output − ... Read More

Set Categorical Column Values to Numeric in R Data Frame

Nizamuddin Siddiqui
Updated on 03-Nov-2021 07:55:36

3K+ Views

To set values in categorical column to numeric values in R data frame, we can use combine function c.For Example, if we have a data frame called df that contains a categorical column say C which has two categories as Low and High and if we want to represent these categories with 1 and 10 then we can use the below command −df$C

Add Caption in a ggplot2 Graph in R

Nizamuddin Siddiqui
Updated on 03-Nov-2021 07:52:30

679 Views

To add a caption in a ggplot2 graph in R, we can use labs function. For Example, if we have a data frame called df that contains two columns say X and Y and we want to create scatterplot between X and Y with a caption as a Note that says “Linear Relation Display” then we can use the below command −ggplot(df,aes(X,Y))+geom_point()+labs(caption="Note: Linear Relation Display")ExampleFollowing snippet creates a sample data frame −x

Change Legend for Multiple Histograms using ggplot2 in R

Nizamuddin Siddiqui
Updated on 03-Nov-2021 07:48:50

1K+ Views

If we create histogram for multiple categories using ggplot2 then the legend is generated automatically based on the categories. And if we want to change that legend or create a histogram with different legend values having different colors for histograms then scale_fill_manual function can be used as shown in the below example.ExampleFollowing snippet creates a sample data frame −Height

Find Location of Installed Packages in R on Windows

Nizamuddin Siddiqui
Updated on 03-Nov-2021 07:45:27

4K+ Views

To find the location of installed packages in R in windows operating system, we can use the command mentioned below −.libPaths()This will return the location of installed packages in the first line and the program files in the second line.Use the below mentioned code to find the location of installed packages in windows operating system −.libPaths() OutputIf you execute the given snippet, it generates the following Output −[1] "C:/Users/Nizam/Documents/R/win-library/4.0" [2] "C:/Program Files/R/R-4.0.4/library"Use the below mentioned code to find the location of installed packages in windows operating system −installed.packages()[1:20, ] OutputIf you execute all the above given snippets as a single ... Read More

Make All Values in an R Data Frame Unique

Nizamuddin Siddiqui
Updated on 03-Nov-2021 07:41:54

520 Views

To make all values in an R data frame unique, we can use make.unique function but firstly we would need to unlist the data frame values and read them with as.character. For Example, if we have a data frame called df that contains duplicate as well as nonduplicate values then we can make all the values unique by using the below command −df[]

Recursive Sum of Digits is Prime or Not in C++

Sunidhi Bansal
Updated on 03-Nov-2021 07:40:46

618 Views

Given an integer variable number as input. The goal is to calculate the sum of digits of the input number and check if that sum is prime or not. Do this till the obtained number with sum of digits becomes a single digit number. Check if that number is prime or not. If the input number is 123 than the sum of digits will be 1+2+3=6 which is non-prime and also 6 is a single digit number.Let us see various input output scenarios for thisInput − number=12341Output − Recursive sum of digits of a number is PRIMEExplanation −1+2+3+4+1=111+1=22 is a prime number.Input − ... Read More

Advertisements