Found 26504 Articles for Server Side Programming

How to find the variance of frequency data in R?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 06:28:44

522 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 var 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 command given below −Total_data

Rearrange an array such that arr[i] = i in C++

Sunidhi Bansal
Updated on 02-Nov-2021 06:27:57

424 Views

We are given a positive integer type array, let's say, arr[] of any given size such that elements in an array should value greater than 0 but less than the size of an array. The task is to rearrange an array in such a manner that if arr[i] is ‘i’, if ‘i’ is present in an array else it will set the arr[i] element with the value -1 and print the final result.Let us see various input output scenarios for this −Input − int arr[] = {0, 8, 1, 5, 4, 3, 2, 9 }Output − Rearrangement of an array such that ... Read More

Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’ in C++

Sunidhi Bansal
Updated on 02-Nov-2021 06:20:09

283 Views

We are given a positive integer type array, let's say, arr[] of any given size such that elements in an array should value greater than 0 but less than the size of an array. The task is to rearrange an array in such a manner that if arr[j] is ‘j’ then arr[j] becomes ‘i’ and print the final result.Let us see various input output scenarios for this −Input − int arr[] = {3, 4, 1, 2, 0}Outpu t− Array before Arrangement: 3 4 1 2 0 Rearrangement of an array such that arr[j] becomes i if arr[i] is j is: 4 ... Read More

Rearrange an array so that arr[i] becomes arr[arr[i]] with O(1) extra space using C++

Sunidhi Bansal
Updated on 02-Nov-2021 06:16:33

852 Views

We are given a positive integer type array, let's say, arr[] of any given size such that elements in an array should value greater than 0 but less than the size of an array. The task is to rearrange an array in such a manner that arr[i] becomes arr[arr[i]] within the given O(1) space only and print the final result.Let us see various input output scenarios for this −Input − int arr[] = {0 3 2 1 5 4 }Output − Array before Arrangement: 0 3 2 1 5 4 Rearrangement of an array so that arr[i] becomes arr[arr[i]] with O(1) extra ... Read More

How to find the row means for each matrix stored in an R list?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 06:23:25

357 Views

To find the row mean of all matrices stored in an R list, we can use sapply function along with rowMeans function.For example, if we have a list called LIST that contains some matrices then the row means for each matrix can be found by using the following command −sapply(LIST,rowMeans)Check out the below example to understand how it works.ExampleFollowing snippet creates the matrices −M1

How to find the median of frequency data in R?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 06:22:03

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

C++ program to rearrange an array in maximum minimum form

Sunidhi Bansal
Updated on 02-Nov-2021 06:11:54

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

How to concatenate elements of equal size vectors alternatively in R?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 06:10:10

168 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

How to find the sample size for t test in R?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 06:14:48

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

C++ program to rearrange all elements of array which are multiples of x in increasing order

Sunidhi Bansal
Updated on 02-Nov-2021 06:07:45

434 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

Advertisements