kobekko94 / Yusuke-Flexdashboard-Practice

0 stars 0 forks source link

Finding mean for multiple columns in data frame #9

Open kobekko94 opened 6 years ago

kobekko94 commented 6 years ago

Here, I was trying to make a new data frame (or is this a vector?) with all the mean values of each question:

red_day1 <- data.frame(matrix(sample(1, 18, replace=TRUE), ncol=18))
  red_day1_mean <- colMeans(red_day1)
  red_day1_mean

I get the of following table with values of only “1”:

 X1  X2  X3  X4  X5  X6  X7  X8  X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 
  1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1 

I tried this alternative approach:

red_day1_mean <- colMeans(day1, na.rm = FALSE, dims = 1:18)
red_day1_mean

But I get the following error:

first element used of 'length.out' argumentError in dimnames(x)[[dims + 1L]] : recursive indexing failed at level 2

Any idea why I get these outputs? Any suggestions how to solve this?

davclark commented 6 years ago

I have tried to answer this in a new file called basic-r.Rmd. Please put code directly in the repo. It's much more efficient to work that way!