Programming Articles - Page 913 of 3363

Recursive insertion and traversal linked list in C++

Sunidhi Bansal
Updated on 03-Nov-2021 06:53:40

1K+ Views

We are given with integer values that will be used to form a linked list. The task is to firstly insert and then traverse a singly linked list using a recursive approach.Recursive addition of nodes at the endIf head is NULL → add node to headElse add to head( head → next )Recursive traversal of nodesIf head is NULL → exitElse print( head → next )ExamplesInput − 1 - 2 - 7 - 9 - 10Output − Linked list : 1 → 2 → 7 → 9 → 10 → NULLInput − 12 - 21 - 17 - 94 - 18Output − Linked list ... Read More

How to create boxplots based on two factor data in R?

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

2K+ Views

To create boxplots based on two factor data, we can create facets for one of the factors, where each facet will contain the boxplots for the second factor.For example, if we have a data frame called df that contains two factor columns say F1 and F2 and one numerical column say Num then the boxplot based on these two factors can be created by using the below given command −ggplot(df,aes(F1,Num))+geom_boxplot()+facet_wrap(~F2)ExampleFollowing snippet creates a sample data frame −Gender

How to create table of two factor columns in an R data frame?

Nizamuddin Siddiqui
Updated on 03-Nov-2021 07:03:46

6K+ Views

To create table of two factor columns in an R data frame, we can use table function and with function.For Example, if we have a data frame called df that contains two factor columns say F1 and F2 then we can create table of these two columns by using the below command −with(df,table(F1,F2))Example 1Following snippet creates a sample data frame −Group

How to remove first character from column name in R data frame?

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

4K+ Views

To remove first character from column name in R data frame, we can use str_sub function of stringr package.For Example, if we have a data frame called df that contains two columns say XID and XDV then we can remove X from both the column names by using the below mentioned command −names(df)=str_sub(names(df),2)Example 1Following snippet creates a sample data frame −XColor

How to increase the width of the X-axis line for a ggplot2 graph?

Nizamuddin Siddiqui
Updated on 03-Nov-2021 06:38:19

5K+ Views

To increase the width of the X-axis line for a ggplot2 graph in R, we can use theme function where we can set the axis.line.x.bottom argument size to desired size with element_line.Check out the below Example to understand how it can be done.ExampleFollowing snippet creates a sample data frame −x

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

497 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

276 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

Advertisements