Found 26504 Articles for Server Side Programming

Change the color of X-axis line for a graph using ggplot2.

Nizamuddin Siddiqui
Updated on 03-Nov-2021 06:32:41

7K+ Views

To change the color of X-axis line for a graph using ggplot2, we can use theme function where we can set the axis.line.x.bottom argument color to desired color with element_line.Check out the below Example to understand how it can be done. This might be required when we want to highlight the X-axis for viewers.ExampleFollowing snippet creates a sample data frame −x

Recursive program to linearly search an element in a given array in C++

Sunidhi Bansal
Updated on 03-Nov-2021 06:18:37

2K+ Views

Given an integer array Arr[] containing integer numbers in any order. The goal is to find the input integer val present in the array using recursive search on the array.If val is not found in the input array Arr[] then return -1. Print the index of val if found in Arr[].ExamplesInput −Arr[] = {11, 43, 24, 50, 93, 26, 78} val=26Output − 26 found at index 5Explanation −Elements in the array start from index 0 to index=array length -1. First index=0 last index=6 : 11 != 26, 78 != 26 → 0+1 , 6-1 First index=1 last index=5 : 43 != 26, 26 ... Read More

How to find the row wise mode of strings in an R data frame?

Nizamuddin Siddiqui
Updated on 03-Nov-2021 06:26:36

477 Views

To find the row wise model of strings in an R data frame, we can use apply function along with custom function for mode, if ties will be there then first value will be chosen based on alphabetical ordering.For Example, if we have a data frame called df that contains string values then we can find the row wise mode of strings by using the command given below −df$RowM

How to deal with error 'height' must be a vector or a matrix while creating barplot?

Nizamuddin Siddiqui
Updated on 03-Nov-2021 06:13:32

4K+ Views

The error 'height' must be a vector or a matrix while creating barplot occurs when we provide data frame name instead of column names or read it with as.matrix. If we want to create bar plot for columns in a data frame then the data frame needs to be read as matrix.For Example, if we have a data frame called df then we can create the barplot of columns in df by using the command given below −barplot(as.matrix(df))ExampleFollowing snippet creates a sample data frame −df

Row-wise common elements in two diagonals of a square matrix in C++

Sunidhi Bansal
Updated on 03-Nov-2021 06:15:22

257 Views

Given a 2D square matrix as input. The goal is to find the elements that are common in both its primary and secondary diagonals. If the input matrix is1 2 3 2 2 4 1 4 7Then its primary diagonal is 1 2 7 and the secondary diagonal is 3 2 1. Common element is 2.There will always be at least one common element in both.ExamplesInput − Matrix[][5] = {{1, 2, 1}, {4, 1, 6}, {1, 8, 1}};Output − Row-wise common elements in diagonals:3Explanation − The matrix is:1 2 1 4 1 6 1 8 1Primary diagonal=1 1 1, Secondary diagonal= 1 1 ... Read More

How to find bootstrap confidence interval in R?

Nizamuddin Siddiqui
Updated on 03-Nov-2021 06:03:48

6K+ Views

The bootstrap confidence interval can be found by using the boot function. The bootstrapping is a method of finding inferential statistics with the help of sample data. It is done by drawing a large number of samples with replacement from the same values. Check out the Examples given below to understand how we can create a bootstrap confidence interval.Example 1Following snippet creates a sample data frame −x1

How to find the frequency based on intervals in R data frame?

Nizamuddin Siddiqui
Updated on 03-Nov-2021 05:52:56

1K+ Views

To create intervals, we can use cut function with seq function and if we want to find the frequency based on these intervals then we just need to use table function along with cut function. We need to properly define the values for interval inside cut function. To understand how it can be done, check out the below Examples.Example 1Following snippet creates a sample data frame −x

Find the unique pair combinations of an R data frame column values.

Nizamuddin Siddiqui
Updated on 03-Nov-2021 05:48:46

2K+ Views

To find the unique pair combinations of an R data frame column values, we can use combn function along with unique function.For Example, if we have a data frame called df that contains a column say x then we can find the unique pair combinations of all column values by using the command given below −combn(unique(df$x),2,FUN=paste,collapse=' ')Example 1Following snippet creates a sample data frame −Grp

Create a random sample by ignoring missing values in an R vector.

Nizamuddin Siddiqui
Updated on 03-Nov-2021 05:41:52

383 Views

To create a random sample by ignoring missing values in an R vector, we can use sample function and the negation of is.na with vector name.For Example, if we have a vector called X that contains some NAs then we can create a random sample of size 100 of X values by using the command given below −sample(X[!is.na(X)],100,replace=TRUE)Example 1To create a random sample by ignoring the missing values in an R vector, use the command given below −x1

Row-wise vs column-wise traversal of matrix in C++

Sunidhi Bansal
Updated on 03-Nov-2021 06:08:30

4K+ Views

A matrix can be traversed in two ways. Row-mise traversal visits each row one by one starting from first row then second and so on till the last row. Elements in the row are returned from index 0 to the last index.In Column-wise traversal, elements are traversed from the first column to the last column in order.In 2D matrix M[i][j]. Index i is used for representing rows and index j is used for representing columns. For row-wise traversal, start fromi=0th row and 0

Advertisements