Programming Articles - Page 907 of 3366

Merge Sort Tree in C++

Sunidhi Bansal
Updated on 05-Nov-2021 07:20:07

680 Views

We are given an integer array, a set of segment start and end pointers and a key value and the problem statement here is to find all the values in the given range which are smaller than or equal to the given key value.Let us understand with exampleInput − arr[] = {7, 8 , 1, 4 , 6 , 8 , 10 }Segment 1: start = 2, end = 4, k = 2Segment 2: start = 1, end = 6, k = 3Output − Count of number which are smaller than or equal to key value in the given range are 2 ... Read More

How to check if a matrix has any missing value in R?

Nizamuddin Siddiqui
Updated on 05-Nov-2021 06:41:26

2K+ Views

To check if a matrix has any missing value in R, we can use any function along with is.na function.For Example, if we have a matrix called M then we can use the below command to check whether M contains any missing value or not −any(is.na(M))Example 1Following snippet creates a sample matrix −M1

How to remove line numbers from data.table object in R?

Nizamuddin Siddiqui
Updated on 05-Nov-2021 06:31:38

2K+ Views

To remove line numbers from data.table object in R, we can set row.names to FALSE and print the data.table object.For Example, if we have a data.table object called DT then we can remove line numbers from DT by using the command given below −print(DT,row.names=FALSE)Example 1To load data.table object and create an object use the following snippet to create a data frame −library(data.table) x1

Create stacked bar plot for one categorical variable in an R dataframe.

Nizamuddin Siddiqui
Updated on 05-Nov-2021 06:20:11

1K+ Views

To create stacked bar plot for one categorical variable in an R data frame, we can use ggplot function and geom_bar function of ggplot2 and provide 1 as the X variable inside aes.For Example, if we have a data frame called df that contains a one categorical column say C and one numerical column Num then we can create the stacked bar plot by using the below command −ggplot(df,aes(1,Num,fill=C))+geom_bar(stat="identity")ExampleFollowing snippet creates a sample data frame −x

Find the value in an R data frame column that exist n times.

Nizamuddin Siddiqui
Updated on 05-Nov-2021 06:15:19

196 Views

To find the value in an R data frame column that exist n times, we first need to tabulate the column with factor then extracting the levels of the column after that reading them with as.numeric.Check out the Examples given below to understand how it can be done.Example 1Following snippet creates a sample data frame −x

Memorization (1D, 2D and 3D) Dynamic Programming in Java

Sunidhi Bansal
Updated on 05-Nov-2021 06:53:56

2K+ Views

Memorization is a technique based on dynamic programming which is used to improve the performance of a recursive algorithm by ensuring that the method does not run for the same set of inputs more than once by keeping a record of the results for the provided inputs(stored in an array).Memorization can be achieved by implementing top down approach of the recursive method.Let us understand this scenario with the help of basic Fibonacci example1-D MemorizationWe will be considering a recursive algorithm with only one non constant parameter (only one parameter changes its value) hence this method is called 1-D memorization. The ... Read More

How to round matrix values in R?

Nizamuddin Siddiqui
Updated on 05-Nov-2021 06:06:36

4K+ Views

To round matrix values, we can use round function.For Example, if we have a matrix called M and we want to round the value in M to 2 decimal places by using the below command −M

How to display numbers with decimal in R data frame column?

Nizamuddin Siddiqui
Updated on 05-Nov-2021 05:59:31

7K+ Views

To display numbers with decimal in R data frame column, we can use format function with round function and nsmall argument.For Example, if we have a data frame called df that contains an integer column say X then we can display numbers in X with 2 decimal places by using the below command −df$X

Find array using different XORs of elements in groups of size 4 in Java

Sunidhi Bansal
Updated on 05-Nov-2021 06:03:24

186 Views

We are given with an integer array of size N(size of multiple 4) and we have to perform Xclusive OR operation on the array such that input[1- 4] resembles utility_arr[1- 4] and the conditions of computing is If arr[1 – 4] = {a1, a2, a3, a4} then q[1 – 4] = {a1 ⊕ a2 ⊕ a3, a1 ⊕ a2 ⊕ a4, a1 ⊕ a3 ⊕ a4, a2 ⊕ a3 ⊕ a4}Let us see various input output scenarios for this -In − int[] input = { 5, 2, 3, 4 };Out − Result after XOR operation 4 3 2 5Explanation −An Exclusive-OR gate's output ... Read More

Change the decimal point of every value in an R data frame column.

Nizamuddin Siddiqui
Updated on 05-Nov-2021 05:54:26

4K+ Views

To change the decimal point of every value in an R data frame column, we can use round function.For Example, if we have a data frame called df that contains a column say X and we want to have each value with 3 decimal places then we can use the below command −df$X

Advertisements