Question

Suppose we have the following data: 0.1876798 0.5425627 0.0000000 0.4680425 0.2812897 0.2763695 -0.2048694 0.4441289   0.0000000 0.5694079...

Suppose we have the following data:

0.1876798 0.5425627
0.0000000 0.4680425
0.2812897 0.2763695
-0.2048694 0.4441289  
0.0000000 0.5694079

The data have two columns as above, the first one is beta1 hat the second one is for beta 2 hat.

I want R codes to get

0.1876798 0.5425627

0.2812897 0.2763695

-0.2048694 0.4441289  


I want R codes to delete the rows that have zeros, and find the average for the first column and second column

Note, I want to apply the code for 800 observations.

Homework Answers

Answer #1

beta1=c(0.1876798,0.0000000,0.2812897,-0.2048694,0.0000000)
> beta2=c(0.5425627,0.4680425,0.2763695,0.4441289 ,0.5694079)
> dd = data.frame(beta1,beta2)
>
> ##Go through each row and determine if a value is zero
> row_sub = apply(dd, 1, function(row) all(row !=0 ))
> ##Subset as usual
> new=dd[row_sub,]
> new
beta1 beta2
1 0.1876798 0.5425627
3 0.2812897 0.2763695
4 -0.2048694 0.4441289
> mean_values=apply(new, 2, mean)
> mean_values
beta1 beta2
0.08803337 0.42102037

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
How can I reduce data set by deleting any rows that have all FALSE values for...
How can I reduce data set by deleting any rows that have all FALSE values for every column in that row using pandas. Assuming there are 20+ columns/rows to loop through. Example: The table data below the pandas code should drop/reduce the data to remove the second & fifth row. Treat The Dtype for the True and False values as Bool. id Test1 value1 value2 value3 value4 0.1 1 False False False False 0.2 2 False True True False 0.3...
If I have 128 columns (patients) and 1265 rows (genes) of data; example below. How do...
If I have 128 columns (patients) and 1265 rows (genes) of data; example below. How do I calculate the average of each column (128) in R? I need to know how to write the code in R? > exprs(ALL) 01005 01010 03002 04006 04007 1000_at 7.597323 7.479445 7.567593 7.384684 7.905312 1001_at 5.046194 4.932537 4.799294 4.922627 4.844565 1002_f_at 3.900466 4.208155 3.886169 4.206798 3.416923 1003_s_at 5.903856 6.169024 5.860459 6.116890 5.687997 1004_at 5.925260 5.912780 5.893209 6.170245 5.615210 1005_at 8.570990 10.428299 9.616713 9.937155 9.983809...
If you want to add the current date to the column of "Date" in Table1, which...
If you want to add the current date to the column of "Date" in Table1, which of the following code is correct: A. Dim dr As New Row = Table1.NewRow dr("Date") = Nowadys.ToShortDateString B. Dim dr As DataRow = Table1.NewRow dr("Date") = Now.ToLongDateString C. Dim dr As DataRow = Table1.NewRow dr("Date") = Current.ToShortDateString D. Dim dr As DataRow = Table1.Row dr("Date") = Present.ToLongDateString What's the meaning of "1" in the following line of code: .Item("AvgBooks") = FormatNumber(.Item("Books") / .Item("Number"), 1)...
You want to estimate E[x] and you have two datasets. In the first data set, there...
You want to estimate E[x] and you have two datasets. In the first data set, there are 10 observations. In the second data set there are 100 observations, but these observations involve measurement errors. That is, X tilda = X + e, where e is a classical measurement error. You can only use one dataset, and you want to have a precise estimate in the sense of having a low variance. A) You should always use the first data set...
How can I reduce data set by deleting any rows that have all FALSE values for...
How can I reduce data set by deleting any rows that have all FALSE values for every column in that row using pandas. Example: The table data below the pandas code should drop/reduce the data to remove the second & fifth row. Treat The Dtype for the True and False values as object. id Test1 value1 value2 value3 value4 0.1 1 False False False False 0.2 2 False True True False 0.3 3 True False False False 0.4 4 False...
c) A function named tallied_data() that takes in a nested list (Use this on the data...
c) A function named tallied_data() that takes in a nested list (Use this on the data from part 1, but it should be able to be used to solve similar problems), indices for two columns and returns a tallied list. The inputs are: i) a nested list, ii) an index for the ‘reference column’/ ‘category’ (col_ref) iii) another index for the column to be tallied (col_tally) iv) this function returns a list of tuples where each element is a tuple...
Question (2) [5 marks] (Use R) Suppose you have a company producing cupcakes. Each cupcake is...
Question (2) [5 marks] (Use R) Suppose you have a company producing cupcakes. Each cupcake is supposed to contain 10 grams of sugar. The cupcakes are produced by a machine that adds the sugar in a bowl before mixing everything. You believe the machine does not add 10 grams of sugar for each cupcake. If your assumption is true, the machine needs to be fixed. You stored the level of sugar of thirty cupcakes. Note: You can create a randomized...
1)Suppose we have two planets with the same mass, but the radius of the second one...
1)Suppose we have two planets with the same mass, but the radius of the second one is twice the size of the first one. How does the free-fall acceleration on the second planet compare to the first planet? 2) Consider two celestial objects with masses m1 and m2 with a separation distance between their centers r. If the separation distance r were to halve (1/2), what would happen to the magnitude of the force of attraction? 3) Consider two celestial...
Use this information to answer the following questions:  We have data here from a sample of middle...
Use this information to answer the following questions:  We have data here from a sample of middle aged people. The columns represent the level of sports they played while the rows represent whether they have developed arthritis later in life. Observed College High school Did not play Arthritis 10 9 24 No arthritis 61 206 548 Run the appropriate test to see if playing sports has an effect on arthritis late in life. What are your hypotheses? Ho: Data fits the...
Use python language please #One of the early common methods for encrypting text was the #Playfair...
Use python language please #One of the early common methods for encrypting text was the #Playfair cipher. You can read more about the Playfair cipher #here: https://en.wikipedia.org/wiki/Playfair_cipher # #The Playfair cipher starts with a 5x5 matrix of letters, #such as this one: # # D A V I O # Y N E R B # C F G H K # L M P Q S # T U W X Z # #To fit the 26-letter alphabet into...