Question

In: Computer Science

1. You are given R function below: TestFunction <- function(df){ M <- rep(0,ncol(df)) for(i in 1:ncol(df)){...

1. You are given R function below:

TestFunction <- function(df){

M <- rep(0,ncol(df)) for(i in 1:ncol(df)){ M[i] <- max(df[,i],na.rm=TRUE) }

return(M) } colMax <- function(df){

M <- rep(0,ncol(df))

for(i in 1:ncol(df)){

M[i] <- max(df[,i])

}

return(M)

}

Describe briefly what this function does

Solutions

Expert Solution

Explanation is given in the columns

Function - 1 :

TestFunction <- function(df){ # this function computes the dataframe df

M <- rep(0,ncol(df)) # ncol(df) will return the number of columns in the dataframe

# rep functions fills the vector with 0 of size 11 and stores the vector in M

for(i in 1:ncol(df)){ M[i] <- max(df[,i],na.rm=TRUE) }

# returns the max element in every column. A problem can occur, when your data contains # NA values (i.e. missing data). //Here the option na.rm=TRUE within the max function

# says that the NULL values are present in the column and asif it is true ignores NA and

# returns max value. If the na.rm=TRUE is not true then and if the NULL values present in

# the column then max becomes NA. If na.rm=TRUE then the max would be the maximum # number.

return(M) }


Function - 2 :

colMax <- function(df){ # this function computes the dataframe df

M <- rep(0,ncol(df))# ncol(df) will return the number of columns in the dataframe

# rep functions fills the vector with 0 of size 11 and stores the vector in M

for(i in 1:ncol(df)){

M[i] <- max(df[,i])

# returns the max element in every column. A problem can occur, when your data contains # NA values (i.e. missing data). //Here the option na.rm=TRUE within the max function

# says that the NULL values are present in the column and asif it is true ignores NA and

# returns max value. If the na.rm=TRUE is not true then and if the NULL values present in

# the column then max becomes NA. If na.rm=TRUE then the max would be the maximum # number.

}

return(M)

}


Related Solutions

3. Given is the function f : Df → R with F(x1, x2, x3) = x...
3. Given is the function f : Df → R with F(x1, x2, x3) = x 2 1 + 2x 2 2 + x 3 3 + x1 x3 − x2 + x2 √ x3 . (a) Determine the gradient of function F at the point x 0 = (x 0 1 , x0 2 , x0 3 ) = (8, 2, 4). (b) Determine the directional derivative of function F at the point x 0 in the direction given...
Given the following periodic function; ?(?) = ?, 0 ≤ ? < 1 ?(?−1)=?(?), ?≥1 i....
Given the following periodic function; ?(?) = ?, 0 ≤ ? < 1 ?(?−1)=?(?), ?≥1 i. Sketch the graph of the function, and ii. Find its Laplace Transform
A probability density function on R is a function f :R -> R satisfying (i) f(x)≥0...
A probability density function on R is a function f :R -> R satisfying (i) f(x)≥0 or all x e R and (ii) \int_(-\infty )^(\infty ) f(x)dx = 1. For which value(s) of k e R is the function f(x)= e^(-x^(2))\root(3)(k^(5)) a probability density function? Explain.
Suppose a function f : R → R is continuous with f(0) = 1. Show that...
Suppose a function f : R → R is continuous with f(0) = 1. Show that if there is a positive number x0 for which f(x0) = 0, then there is a smallest positive number p for which f(p) = 0. (Hint: Consider the set {x | x > 0, f(x) = 0}.)
Let f: [0 1] → R be a function of the class c ^ 2 that...
Let f: [0 1] → R be a function of the class c ^ 2 that satisfies the differential equation f '' (x) = e^xf(x) for all x in (0,1). Show that if x0 is in (0,1) then f can not have a positive local maximum at x0 and can not have a negative local minimum at x0. If f (0) = f (1) = 0, prove that f = 0
Let A∈Mn(R)"> A ∈ M n ( R ) A∈Mn(R) such that I+A"> I + A I+A is invertible. Suppose that
Let A∈Mn(R)A∈Mn(R) such that I+AI+A is invertible. Suppose thatB=(I−A)(I+A)−1B=(I−A)(I+A)−1(a) Show that B=(I+A)−1(I−A)B=(I+A)−1(I−A) (b) Show that I+BI+B is invertible and express AA in terms of BB.
Let function F(n, m) outputs n if m = 0 and F(n, m − 1) +...
Let function F(n, m) outputs n if m = 0 and F(n, m − 1) + 1 otherwise. 1. Evaluate F(10, 6). 2. Write a recursion of the running time and solve it . 3. What does F(n, m) compute? Express it in terms of n and m.
1. Evaluate the double integral for the function f(x,y) and the given region R. R is...
1. Evaluate the double integral for the function f(x,y) and the given region R. R is the rectangle defined by -2  x  3 and 1   y  e4 2. Evaluate the double integral    f(x, y) dA R for the function f(x, y) and the region R. f(x, y) = y x3 + 9 ; R is bounded by the lines x = 1, y = 0, and y = x. 3. Find the average value of the function f(x,y) over the plane region R....
construct a bijective function of f:[0, inf) -> R   
construct a bijective function of f:[0, inf) -> R   
It is given that M = 185 kg and R = 1.65 m. What if an...
It is given that M = 185 kg and R = 1.65 m. What if an inner solid cylinder is cut out from it, with a radius of (1/2)R? a) What is the moment of inertia around the central axis (as in the example) of this inner cylinder? b) What is the moment of inertia of the remaining hollow cylinder around the same axis? (Notice that all answers are independent of the length L.)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT