
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 33676 Articles for Programming

500 Views
When we create a sample using inbuilt or imported data set then the numbering for selected rows as in the original data set, therefore, the numbering becomes unordered. To change this unordered numbering to a sequence say starting from one to the total number of rows in the sample, we can use 1:nrow(“sample_object_name”).Consider the below data frame −Example Live Demoset.seed(999) x
Program to find k-sized list where difference between largest and smallest item is minimum in Python

217 Views
Suppose we have a list of numbers called nums and an integer k, we have to select elements from nums to create a list of size k such that the difference between the largest integer in the list and the smallest integer is as low as possible. And we will return this difference.So, if the input is like nums = [3, 11, 6, 2, 9], k = 3, then the output will be 4, as the best list we can make is [2, 3, 6].To solve this, we will follow these steps −sort the list numsls := a new listfor ... Read More

675 Views
The two plots created by using ggplot2 can be arranged in a vertical manner with the help gridExtra package, we simply needs to use grid.arrange function to do so. For example, if we have two plots created by using ggplot2 and saved in objects p1 and p2 then they can be vertically arranged as grid.arrange(p1,p2)Consider the below data frame −Exampleset.seed(151) x

7K+ Views
If we have small number of rows then we might want to create bar plot for rows instead of using columns as categories. This can be done by using barplot function but we need to convert the data frame to matrix and take the transpose of it. For example, if we have a data frame data_frame with 4 rows and 4 columns, then the barplot with rows as categories can be created as barplot(t(as.matrix(data_frame)),beside=TRUE)Consider the below data frame −Example Live Demox1

237 Views
Suppose we have a list of strings words, we have to group all anagrams together and return the size of the largest grouping.So, if the input is like words = ["xy", "yx", "xyz", "zyx", "yzx", "wwwww"], then the output will be 3, as ["xyz", "zyx", "yzx"] is the largest grouping.To solve this, we will follow these steps −lookup := a new map, initially emptyres := 0for each i in words, dop := sort i in lexicographical wayif p is in lookup, increase count, otherwise 1res := maximum of res and lookup[p]return resLet us see the following implementation to get better ... Read More

1K+ Views
When we have a single long string or a vector of string values and the values within the string are separated by some special characters then splitting the values can help us to properly understand those strings. This could happen in situations when the string data is recorded with mistakes or have some other purpose. We can do the splitting using strsplit function.Example Live Demox1

465 Views
Suppose we have a string s of lowercase alphabet characters, and another number k, we have to find the minimum number of required changes in the string so that the resulting string has at most k distinct characters. In this case The change is actually changing a single character to any other character.So, if the input is like s = "wxxyyzzxx", k = 3, then the output will be 1, as we can remove the letter "w" to get 3 distinct characters (x, y, and z).To solve this, we will follow these steps −count := a map of each character ... Read More

447 Views
To plot all the values of an R data frame, we can use matplot function. This function plots all the values based on the columns of an R data frame and represent them by the column number. For example, if we have five columns in an R data frame then matplot will represent the first column by 1, second column by 2, third column by 3 and so on.Consider the below data frame −Example Live Demoset.seed(555) v1

537 Views
The proportion of row values can be calculated if we divide each row value with the sum of all values in a particular row. Therefore, the total sum of proportions will be equal to 1. This can be done by dividing the data frame with the row sums and for this purpose we can use the below syntax −Syntaxdata_frame_name/rowSums(data_frame_name)Consider the below data frame −Example Live Demoset.seed(111) x1

541 Views
Suppose we have a list of sorted unique numbers called nums and an integer k, we have to find the kth missing number from the first element of the given list.So, if the input is like nums = [5, 6, 8, 10, 11], k = 1, then the output will be 9, as 9 is the second (index 1) missing number.To solve this, we will follow these steps −for i in range 1 to size of nums, dodiff := nums[i] - nums[i - 1] - 1if k >= diff, thenk := k - diffotherwise, return nums[i - 1] + k ... Read More