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
Programming Articles - Page 912 of 3366
4K+ Views
To find the row corresponding to a nearest value in an R data frame, we can use which.min function after getting the absolute difference between the value and the column along with single square brackets for subsetting the row.To understand how it works, check out the examples given below.Example 1Following snippet creates a sample data frame −ID
3K+ 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 a clockwise direction such that the last row becomes the first column, second row becomes second column and first 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 in clockwise direction without using any ... Read More
176 Views
We are given an integer type value, let's say, number. The task is to check whether the given number is Refactorable or not. If yes print that the number is a refactorable number else print not possible.What is a Refactorable Number?A number is refactorable when it is divisible by its total count of factors available. For example, number 9 is refactorable as it has a total number of factors i.e. 3(1, 3, 9) and 9 is divisible by 3 hence its a refactorable number.Let us see various input output scenarios for this −Input − int number = 9Output − It is a ... Read More
1K+ Views
We are given a string, let's say, str of any given length. The task is to rearrange the given string in such a manner that there won't be the same adjacent characters arranged together in the resultant string.Let us see various input output scenarios for this −Input − string str = "itinn"Output − Rearrangement of characters in a string such that no two adjacent are same is: initn.Explanation − We are given a string type variable let’s say, str. Now we will rearrange the characters of an input string in such a manner that no two same characters occur at the same position ... Read More
411 Views
The easiest way to find the frequency is to create a table for the provided vector or data frame column and it can be done with table function. But, if the frequency needs to be found with subsetting then subset function and transform function will also be required as shown in the below examples.Example 1Following snippet creates a sample data frame −head(ChickWeight, 20)OutputThe following dataframe is created − weight Time Chick Diet 1 42 0 1 1 2 51 2 1 1 3 59 4 1 1 4 ... Read More
299 Views
Given an area of rectangle as input. The goal is to find the sides of a rectangle such that the difference between the length and breadth is minimum.Area of Rectangle = length * breadth.ExamplesInput − Area = 100Output −Side of Rectangle with minimum difference:Length = 10, Breadth = 10Explanation − Sides with area = 100.2 - 50, 4 - 25, 5 - 20, 10 - 10. Sides with minimum difference are 10-10 with difference = 0. As we know tha square is a rectangle with equal length on all sides.Input − Area = 254Output − Side of Rectangle with minimum difference :Length = 127, Breadth ... Read More
2K+ Views
To create a block diagonal matrix using a matrix in R, we can use bdiag function of Matrix package.For Example, if we have a matrix called M and we want to create block diagonal using M 4 times by using the below command −bdiag(replicate(4,M,simplify=FALSE))Check out the Examples given below to understand how it can be done.Example 1Following snippet creates a sample matrix −M1
3K+ Views
The sub totals for every row and column are actually called marginal sums. Therefore, we can use addmargins function to our table to get the sub totals for every row and column.For example, if we have table called TABLE then we can add the sub totals by using the command given below −TABLE
714 Views
Given a string str1 as input. The goal is to insert a ‘*’ between a pair of identical characters in the input string and return the resultant string using a recursive approach.If the input string is str1= "wellness" then output will be "wel*lnes*s"ExamplesInput − str1="happiness"Output − String after adding * : hap*pines*sExplanation − Adding * between pairs pp and ss will gives us resultant string hap*pines*sInput − str1=”swimmmmingggg pooool”Output − String after adding * : swim*m*m*ming*g*g*g po*o*o*olExplanation − Adding * between pairs mm, gg and oo will gives us resultant string swim*m*m*ming*g*g*g po*o*o*olApproach used in the below program is as followsIn this approach take string ... Read More
968 Views
To find the sample size for two sample proportion tests with given power, we can use the function power.prop.test where we need to at least pass the two proportions and power.By default the significance level will be taken as 0.05 and if we want to change it then sig.level argument will be used.Given below are some examples with the display of significance levels.Example 1Use the code given below to find the sample size for two sample proportion tests −power.prop.test(p1=8/20, p2=6/20, power=0.90, sig.level=0.05)OutputIf you execute the above given snippet, it generates the following Output for the two-sample comparison of proportions power ... Read More