Question

In: Computer Science

MUST BE SOLVED USING [R] How to get the nth largest even value of given array?...

MUST BE SOLVED USING [R]

How to get the nth largest even value of given array? (Use while loop and if-statement for this problem. Do not use existing codes. Use your own codes). DO NOT USE ANY KINDS OF SORT FUNCTIONS.

For example, in given list [10,36,58,31,56,77,43,12,65,19], if n is defined as 2. The program will print 56.

Solutions

Expert Solution

n_largest_even<-function(array,n)
{
even_array=c();
ind=1;
for (i in array)
{if(i%%2==0)
{even_array[ind]=i;ind=ind+1; }
}
for (i in 1:length(even_array))
{a=1:(length(even_array)-i-1);
if(length(a)==1)
break;
for (j in a)
{
if (even_array[j] < even_array[j+1])
{temp=even_array[j];even_array[j]=even_array[j+1];even_array[j+1]=temp;}
}}
return (even_array[n]);
}
lis=c(10,36,58,31,56,77,43,12,65,19)
n_largest_even(lis,2)


Related Solutions

In python please :) How to get the n th smallest even value of given array?...
In python please :) How to get the n th smallest even value of given array? (Use for loop for this problem. Do not use existing codes. Use your own codes). For example, in given list [11,23,58,31,56,22,43,12,65,19], if n is defined as 3. The program will print 56. (By using for loop and obtain the set of evens. By using another for loop, from the set of evens remove (n-1) observations and break the loop and find the minimum observation...
I want this to be solved using R studio or R software, please. Here is the...
I want this to be solved using R studio or R software, please. Here is the example: The data in stat4_prob5 present the performance of a chemical process as a function of sever controllable process variables. (a) Fit a multiple regression modelrelating CO2product (y) to total solvent (x1) and hydrogen consumption (x2) and report the fitted regression line. (b) Find a point estimatefor the variance term σ2. (c) Construct the ANOVA tableand test for the significance of the regression using...
Even before the structure of DNA was solved, studies indicated that the genetic material must have...
Even before the structure of DNA was solved, studies indicated that the genetic material must have the following properties: • be able to store information; • be faithfully replicated and be passed on from generation to generation; and • allow for changes, and thus evolution, to occur.   1: Explain how the structure of the double helix showed that DNA had these properties. Write one or two sentences per point. 2:Linus Pauling's model was wrong because it didn't ? 3: he...
Consider the following algorithm to find the kth largest elementof a given array A of...
Consider the following algorithm to find the kth largest element of a given array A of n numbers. We pick every fifth element of A and place them in the array B. We find the median of B recursively, and use this median of B as a pivot to partition the array A. Depending on k and the number of elements that are smaller than the chosen pivot, we recurse into an appropriate subproblem of A.Answer the following questions.Write the...
Writing an nth root program in C++ using only: #include using namespace std; The program must...
Writing an nth root program in C++ using only: #include using namespace std; The program must be very basic. Please don't use math sqrt or pow . For example, the 4th root of 16 is 2 because 2 * 2 * 2 * 2 = 16. The 4th root of 20 is 2 because 2 * 2 * 2 * 2 = 16 and 16 is less than 20, and 3 * 3 * 3 * 3 = 81, which...
Write a C++ program to find K largest elements in a given array of integers. For...
Write a C++ program to find K largest elements in a given array of integers. For eeample, if K is 3, then your program should ouput the largest 3 numbers in teh array. Your program is not supposed to use any additional array.
Python - You are given a sorted (from smallest to largest) array A of n distinct...
Python - You are given a sorted (from smallest to largest) array A of n distinct integers which can be positive, negative or zero. Design the fastest algorithm you can for deciding if there is an index i such that A[i] = i.
The following code must be written using matlab How to get the elements that are different...
The following code must be written using matlab How to get the elements that are different in two set without using the setdiff function in matlbab?
This exercise is to be solved using program R. Information about worms that inhabit various conditions...
This exercise is to be solved using program R. Information about worms that inhabit various conditions was obtained (Worms.txt). Suppose that the mean of Worm.density is 5, then you want to conduct a statistical test. (H0: mu=5 vs H1: mu≠5) Find t statistics. Compare t statistics with t distribution table and conclude with a significant level of 5%. Show the code and Rhistory. Worms.txt Field.Name Area Slope Vegetation Soil.pH Damp Worm.density Nashs.Field 3.6 11 Grassland 4.1 F 4 Silwood.Bottom 5.1...
In Java Find the second largest and second smallest element in a given array. You can...
In Java Find the second largest and second smallest element in a given array. You can hardcode/declare the array in your program.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT