Articles on Trending Technologies

Technical articles with clear explanations and examples

Reverse actual bits of the given number in Java

Sunidhi Bansal
Sunidhi Bansal
Updated on 03-Nov-2021 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 values in categorical column to numeric values in R data frame.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 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

Read More

How to add a caption in a ggplot2 graph in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 739 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

Read More

How to change legend for multiple histograms using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 2K+ 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

Read More

How to find the location of installed packages in R in windows operating system?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 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

How to make all values in an R data frame unique?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 581 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[]

Read More

Recursive sum of digits of a number is prime or no in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 03-Nov-2021 671 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

How to find the row corresponding to a nearest value in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 4K+ Views

To find the row corresponding to a nearest value in an R data frame, we can use which.min function after getting the absolute difference between the value and the column along with single square brackets for subsetting the row.To understand how it works, check out the examples given below.Example 1Following snippet creates a sample data frame −ID

Read More

How to find the frequency with subsetting in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 464 Views

The easiest way to find the frequency is to create a table for the provided vector or data frame column and it can be done with table function. But, if the frequency needs to be found with subsetting then subset function and transform function will also be required as shown in the below examples.Example 1Following snippet creates a sample data frame −head(ChickWeight, 20)OutputThe following dataframe is created − weight Time Chick Diet 1   42   0   1     1 2   51  2    1     1 3   59  4    1     1 4 ...

Read More

Recursive sum of digits of a number formed by repeated appends in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 03-Nov-2021 466 Views

Given two integers ‘number’ and ‘repeat’ as input. The goal is to calculate the sum of digits of the input number repeated ‘repeat’ number of times until the sum becomes a single digit. Do this till the obtained number with sum of digits becomes a single digit number. If the input number is 123 and repeat=2 than the sum of digits of 123123 will be 1+2+3+1+2+3=12 which is not a single digit number. Now the sum of digits of 12 is 1+2=3. Output will be 3Let us see various input output scenarios for thisInput − number=32 repeat=3Output − Recursive sum of digits ...

Read More
Showing 47661–47670 of 61,297 articles
Advertisements