Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9171081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:06:52+00:00 2026-06-17T16:06:52+00:00

I have created a dataframe killers with 3 variables. The data are numeric though

  • 0

I have created a dataframe “killers” with 3 variables. The data are numeric though there exist NA values throughout.

My goal is to calculate the mean on each of the 3 variables.

sapply(killers, function(x) median)

This returns:

$heartattack
function (x, na.rm = FALSE) 
UseMethod("median")
<bytecode: 0x103748108>
<environment: namespace:stats>

I know that the na.rm argument is a means to ignore NA values. Since na.rm = FALSE exists in what was returned by R, one presumes that there is a way to set this to TRUE within the line of code above. I tried a few variations:

sapply(killers, na.rm=TRUE function(x) median)
sapply(killers, function(x) median, na.rm=TRUE)
sapply(killers, function(x) median(na.rm=TRUE))

I’m not sure if I’m close or if this is going to involve nesting functions, as per other similar (though ultimately not helpful in this instance that I can see) posts on the topic on SO. e.g.
How to pass na.rm as argument to tapply?,
Ignore NA's in sapply function

Of course, I could just calculate the mean on each vector that was used to create killers, but surely if what I’m asking is possible then that is better.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:06:53+00:00Added an answer on June 17, 2026 at 4:06 pm

    Just do:

    sapply(killers, median, na.rm = TRUE)
    

    An alternative would be (based on your code)

    sapply(killers, function(x) median(x, na.rm=TRUE)) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using python I have created following data frame which contains similarity values: cosinFcolor cosinEdge
I have a data.frame called series_to_plot.df which I created by combining a number of
I have a data frame with several variables. What I want is create a
I have a dataframe with numerical columns. For each column I would like calculate
I created a data frame in longformat which has 5 variables( company name, key
I have created a Pandas DataFrame df = DataFrame(index=['A','B','C'], columns=['x','y']) Now, I would like
I have a dataframe (data) which includes a lot of dates. I want to
I have a dataframe in R with three variables named for example df$V1 ,
I have created a data frame my.df and wish to select rows (or delete
I have created an empty data frame using another data frame with the below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.