Programming Articles

Page 2167 of 2547

Merge k sorted arrays in Java

Sunidhi Bansal
Sunidhi Bansal
Updated on 05-Nov-2021 807 Views

We are given an ‘n’ number of arrays, let's say we take three arrays i.e. arr1[], arr2[] and arr3[] of integer type. The task is to merge all the given integer arrays in such a manner that the resultant array is sorted in the runtime only.Let us understand with exampleInput −Inta[]={21, 22, 23, 24};int b[ ] ={28, 31, 35}Output −int resultant[ ]={21, 22, 23, 24, 28, 31, 35}.Explanation − The array elements are compared before they are added and added according to their suitable position in the resultant array.Input −inta[]={1, 3, 5, 7, 9, 11, 13};int b[ ] ={14, 16, 18}int c[ ] ={19, ...

Read More

Find the missing numbers in a sequence in R data frame column.

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

To find the missing numbers in a sequence in R data frame column, we can use setdiff function.For Example, if we have a data frame called df that contains a column say X and we want to check which values between 1 to 20 are missing in this column then we can use the below command −setdiff(1:20,df$X)Example 1Following snippet creates a sample data frame −x

Read More

How to extract columns having at least one non-duplicate in R?

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

To extract columns from an R data frame having at least one non-duplicate, we can use Filter function.For Example, if we have a data frame called df that contains some columns having duplicate values and columns that do not contains at least one non-duplicate then we can extract columns having at least one non-duplicate by using the below command −Filter(var,df)Example 1Following snippet creates a sample data frame −x1

Read More

Create bar plot for grouped data of two columns in base R.

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

To create bar plot for grouped data in base R, we can create the table for both the columns and then use beside argument of barplot function to create the bar plot. To differentiate between the bars, we need to set legend argument to TRUE as well. To understand how it can be done check out the below Example.ExampleFollowing snippet creates a sample data frame −G

Read More

Get a matrix as Output if a condition for a single value is met in R.

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

If we want to check a condition and the Output based on that condition needs to be a matrix then we can use if else function in R.For Example, if we have a value say V = 5 and we want to get matrix M1 if V is equal to 5 and matrix M2 if V is not equal to 5 then we can use the below command −if (V == 5) M1 else M2ExampleFollowing snippet creates a sample matrices −M1

Read More

How to create normal probability plot in R with confidence interval bands?

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

To create normal probability plot in R with confidence interval bands, we can use qqPlot function of QTLRel package. We simply need to pass the vector name that contains normal distribution values inside qqPlot function or directly introduce the vector inside the function as shown in the below given examples.Example 1Use the following code to create normal probability plot −library("QTLRel") qqPlot(rnorm(10))OutputIf you execute the above given snippet, it generates the following Output −Example 2Add the following code to the above snippet to create normal probability plot −qqPlot(rnorm(500)) OutputIf you execute the above given snippet, it generates the following Output −Example ...

Read More

Create a matrix for odd number of elements by filling the last element with NA in R.

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

We can find the total number of elements for a matrix with the help of prod and dim function as shown in the below Examples. To create a matrix for odd number of elements by filling the last element with NA, we can use byrow argument.For Example, if we have a vector called V that contains 19 elements then we can create a matrix called M having 20 elements NA as the last element by using the below command −M

Read More

How to create an ID column in R based on categories?

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

If we have a categorical column in an R data frame then it can be used to create an ID column where each category will have its own ID defined on the basis of categories in the categorical column.For this purpose, we would need to read the categorical column with as.factor and as.numeric function as shown in the below examples.Example 1Following snippet creates a sample data frame −Group

Read More

Rotate a matrix by 90 degree without using any extra space in C++

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

We are given a 2-D array that will be used to form a matrix pattern. The task is to rotate a matrix by 90 degrees in an anti-clockwise direction such that the first row becomes the first column, second row becomes second column and third becomes third column and the challenge is that we don’t have to use any extra space.Let us see various input output scenarios for this −Input −int arr[row_col_size][row_col_size] = { { 5, 1, 4},    { 9, 16, 12 },    { 2, 8, 9}}Output   −Rotation of a matrix by 90 degree without using any extra space ...

Read More

How to create a scatterplot with larger distance between facets in R?

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

By default, the distance/space between facets created by using ggplot2 is very less and it becomes a little uneasy for viewers to separately read the facets. Therefore, to deal with this problem we can increase the space between facets and it can be done with the help of theme function as shown in the example below.ExampleFollowing snippet creates a sample data frame &miuns;x

Read More
Showing 21661–21670 of 25,466 articles
Advertisements