Found 26504 Articles for Server Side Programming

Rearrange array such that even positioned are greater than odd in C++

Sunidhi Bansal
Updated on 02-Nov-2021 06:43:15

336 Views

We are given an integer type array containing both positive and negative numbers, let's say, arr[] of any given size. The task is to rearrange an array in such a manner that all the elements at an even position or index should be greater than the elements at an odd position or index and print the result.Let us see various input output scenarios for this −Input − int arr[] = {2, 1, 4, 3, 6, 5, 8, 7}Output − Array before Arrangement: 2 1 4 3 6 5 8 7 Rearrangement of an array such that even positioned are greater than odd ... Read More

Rearrange array such that even index elements are smaller and odd index elements are greater in C++

Sunidhi Bansal
Updated on 02-Nov-2021 06:40:49

488 Views

We are given an integer type array containing both positive and negative numbers, let's say, arr[] of any given size. The task is to rearrange an array in such a manner that all the elements at an even position or index should be less than the elements at an odd position or index and print the result.Let us see various input output scenarios for this −Input − int arr[] = {2, 1, 4, 3, 6, 5, 8, 7}Output − Array before Arrangement: 2 1 4 3 6 5 8 7 Rearrangement of an array such that even index elements are smaller and ... Read More

How to find the trimmed mean for a column of an R data frame?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 06:55:54

609 Views

Trimmed mean is the mean that find the mean of values by excluding a small percentage of smallest and largest values. If we have a 5% trimmed mean that means 2.5% of smallest values and 2.5% of largest values are trimmed from the data and then the mean of the remaining data is calculated.In R, we can simply use trim argument inside mean function to find the trimmed mean. Check out the below Examples to understand how it can be done.Example 1Following snippet creates a sample data frame −x

Rearrange array in alternating positive & negative items with O(1) extra space in C++

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

711 Views

We are given an integer type array containing both positive and negative numbers, let's say, arr[] of any given size. The task is to rearrange an array in such a manner that there will be a positive number that will be surrounded by negative numbers. If there are more positive and negative numbers, then they will be arranged at the end of an array.Let us see various input output scenarios for this −Input − int arr[] = {-1, -2, -3, 1, 2, 3}Output − Array before Arrangement: -1 -2 -3 1 2 3 Rearrangement of an array in alternating positive & negative ... Read More

Rearrange an array to minimize sum of product of consecutive pair elements in C++

Sunidhi Bansal
Updated on 02-Nov-2021 06:34:37

445 Views

We are given a positive integer type array, let's say, arr[] of any given size. The task is to rearrange an array in such a manner that when we multiply an element with its alternative element and then add all the resultant elements then it should return the minimum sum.Let us see various input output scenarios for this −Input − int arr[] = {2, 5, 1, 7, 5, 0, 1, 0}Output − Rearrangement of an array to minimize sum i.e. 7 of product of consecutive pair elements is: 7 0 5 0 5 1 2 1Explanation − we are given an integer array ... Read More

How to deal with error “var(x) : Calling var(x) on a factor x is defunct.” in R?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 06:56:50

4K+ Views

The error “Calling var(x) on a factor x is defunct” occurs when we try to apply a numerical function on factor data.For example, if we have a factor column in a data frame then applying numerical functions on that column would result in the above error. To deal with this problem, we can use as.numeric function along with the numerical function as shown in the below examples.Example 1Following snippet creates a sample data frame −x

Roll up R data frame columns for summation by group if missing values exist in the data frame.

Nizamuddin Siddiqui
Updated on 02-Nov-2021 06:50:37

499 Views

The summation of column values if missing values exist in the R data frame can be found with the help of summarise_each function of dplyr package where we can remove missing values by setting na.rm argument to TRUE.Since, we we will have groups in the data frame hence group_by function of the same package will help the summarise_each function to perform the summation by group. Check out the below Examples to understand how it works.Example 1Following snippet creates a sample data frame −Grp

Rearrange an array such that every odd indexed element is greater than its previous in C++

Sunidhi Bansal
Updated on 02-Nov-2021 06:31:03

221 Views

We are given a positive integer type array, let's say, arr[] of any given size. The task is to rearrange an array in such a manner that all the elements present at an odd index should value greater than the element presents at an even index and print the result.Let us see various input output scenarios for this −Input − int arr[] = {2, 1, 5, 4, 3, 7, 8}Output − Array before Arrangement: 2 1 5 4 3 7 8 Rearrangement of an array such that every odd indexed element is greater than it previous is: 1 4 2 5 3 ... Read More

How to create a base R plot without axes but keeping the frame of the plot?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 06:37:11

382 Views

To create a base R plot without axes but keeping the frame of the plot, we can set axes argument to FALSE and frame.plot argument to TRUE.For example, if we have a vector called V and we want to create a plot of V without axes but with the frame of the plot then, we can use the command given below −plot(V,axes=FALSE,frame.plot=TRUE)Check out the below example to understand how it works.ExampleConsider the following snippet −x

How to find the autocorrelation values from ACF plot in R?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 06:27:11

4K+ Views

The autocorrelation plot or ACF plot is a display of serial correlation in data that changes over time. The ACF plot can be easily created by using acf function.For example, if we have a vector called V then we can create its autocorrelation plot by using the command acf(V). If we want to extract autocorrelation values then we would need to save the plot values in an object by using the below command. This will not create the plot.Autocorrelation_x

Advertisements