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 922 of 3363
1K+ Views
If we have frequency data then we first need to find the total data or complete data by repeating the values up to the frequency corresponding to each value after that we can apply median function on this complete data.For Example, if we have a data frame called df that contains two columns say X and Frequency then we can find the total data by using the following command −Total_data
2K+ Views
We are given an integer array which can be arranged in sorted/unsorted manner. The task is to first sort the array if the values are unsorted then arrange the array in such a manner that the first element of array will be the maximum value, second will be the minimum value, third will be the second largest value, fourth will be the second minimest value and so on.Let us see various input output scenarios for this −Input − int arr[] = {7, 5, 2, 3, 4, 9, 10, 5 }Output − Array before Arrangement: 2 3 4 5 5 7 9 10 ... Read More
201 Views
If we have multiple vectors and we want to combine the vector elements alternatively then we can use rbind function along with c function.For Example, if we have three vectors say X, Y, and Z as −X = 1, 2, 3 Y = 4, 5, 6 Z = 7, 8, 9Then, we can combine the elements in these vectors alternatively by using the below command −c(rbind(X,Y,Z,)) Example 1To concatenate elements of equal size vectors add the following code to the above snippet −x1
4K+ Views
To find the sample size for t test, we can use pwr.t.test function of pwr package, wherever we can pass the arguments for alternative hypothesis such as one-sided or two-sided, significance level, power of the test and difference for two samples.Check out the below examples to understand how it works.Example 1Consider the following code to find sample size for t test −library("pwr") pwr.t.test(power=0.80, d=1, sig.level=0.05, alternative="two.sided")OutputIf you execute the above given code, it generates the following Output for the two-sample t test power calculation − n = 16.71472 d = 1 sig.level = 0.05 power = 0.8 alternative ... Read More
461 Views
We are given an integer type array as ‘int arr[]’ and an integer type variable as ‘x’. The task is to rearrange all the elements of an array in such a manner that they will be divisible by a given integer value ‘x’ and the arrangement should be in an increasing order.Let us see various input output scenarios for this −Input − int arr[] = {4, 24, 3, 5, 7, 22, 12, 10}, int x = 2Output − Rearrangement of all elements of array which are multiples of x 2 in decreasing order is: 4 10 3 5 7 12 22 24Explanation −we ... Read More
2K+ Views
The factor with duplicate levels represents grouping data but if we want to convert the grouping data into nominal data then duplicate values must be removed or converted into unique values. To make duplicate factor levels unique in an R data frame, we can use make.unique function.Check out the below Examples to understand how it works.Example 1Following snippet creates a sample data frame −Factor
4K+ Views
We sometimes need to perform mathematical operations on all values in the data set. One such operation could be dividing each value by 100.For example, if we have a data frame called df then we can divide each value in df by 100 by using the below command −df[,1:ncol(df)]/100ExampleFollowing snippet creates a sample data frame −x1
210 Views
We are given positive integer variables as ‘num’ and ‘x’. The task is to recursively calculate the num ^ x then add the digits of a resultant number till the single digit isn’t achieved and the resultant single digit will be the output.Let us see various input output scenarios for this −Input − int num = 2345, int x = 3Output − Recursive sum of digit in n^x, where n and x are very large are: 8Explanation − we are given positive integer values as num and x with the values as 2345 and power as 3. Firstly, calculate 2345 ^ 3 i.e. ... Read More
202 Views
To find the groupwise common value for a data.table object, we can use Reduce function with intersect function.For example, if we have a data.table object called DT that contains a numerical column say Num and a categorical column say C where C exists at the first position then the groupwise common value can be found by using the command given below −Reduce(intersect,DT[,.(list(unique(Num))),C]$V1)ExampleConsider the below data.table object −Group
1K+ Views
To create ggplot2 graph with reversed Y-axis and X-axis on top, we can use scale_y_reverse and scale_x_continuous function of ggplot2 package.For Example, if we have a data frame called df that contains two columns say X and Y and we want to create the scatterplot between X and Y with reversed Y-axis and X-axis on top then we can use the below command −ggplot(df,aes(X,Y))+geom_point()+scale_y_reverse()+scale_x_continuous(position="top")ExampleFollowing snippet creates a sample data frame −x