Articles on Trending Technologies

Technical articles with clear explanations and examples

How to remove rows that have NA in R data frames stored in a list?

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

To remove rows that have NA in R data frames stored in a list, we can use lapply function along with na.omit function.For example, if we have a list called LIST that contains some data frames each containing few missing values then the removal of rows having missing values from these data frames can be done by using the command given below −lapply(LIST,na.omit)Check out the below given example to understand how it works.ExampleFollowing snippet creates a sample data frame −df1

Read More

Recursive approach for alternating split of Linked List in C++

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

Given a Singly linked list as input. The goal is to split the list into two singly linked lists that have alternate nodes of the original list. If the input list has nodes a → b → c → d → e → f then after the split, two sub-lists will be a → c → e and b → d → f.We will take two pointers N1 and N2 one pointing to the head of the original list and another pointing to the head → next. Now move both pointers to the next of next node and create sublists.ExamplesInput − ...

Read More

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

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

Read More

Recursive insertion and traversal linked list in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 03-Nov-2021 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 increase the width of the X-axis line for a ggplot2 graph?

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

Read More

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

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

Read More

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

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

Read More

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

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

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

Sunidhi Bansal
Sunidhi Bansal
Updated on 03-Nov-2021 311 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 deal with error 'height' must be a vector or a matrix while creating barplot?

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

Read More
Showing 47681–47690 of 61,297 articles
Advertisements