title: Trying to figure out how to return the mean value of each column in a data frame using a list
body: <p>I have a data frame which shows the average life expectancy of a country from 1800 to 2018.The Columns are labeled like this: XYear. For example: X2000. I made a function which returns the mean value of a selected column. Here's the part I'm struggling with: the assignment is asking me to create a list which has the mean value of every column in the data frame, using the aforementioned function.</p>
  
  <p>I tried making a list element which would select all rows and columns except for the first ones (selecting them with [-1,-1]). </p>
  
  <pre><code>life_exp &lt;- read.csv("data/life_expectancy_years.csv", stringsAsFactors = FALSE)
  </code></pre>
  
  <p>Write a function <code>get_col_mean()</code> that takes in a column name and a data frame and returns the mean of that column. Make sure to properly handle NA values</p>
  
  <pre><code>get_col_mean &lt;- function(col_name, data_frame_name) {
  return(mean(data_frame_name[, col_name], na.rm = TRUE))
  }
  </code></pre>
  
  <p>Create a list <code>col_means</code> that has the mean value of each column in the data frame (except the <code>Country</code> column). You should use your function above.</p>
  
  <p>I tried this:
  column_means = get_col_mean(life_exp$life_exp[, -1], life_exp)</p>
  
  <p>But I got this error message:</p>
  
  <blockquote>
    <p>In mean.default(data_frame_name[, col_name], na.rm = TRUE) :
      argument is not numeric or logical: returning NA</p>
  </blockquote>