Remove NA values from the output in R programming

0 votes

I'm trying to find mean of all column values using R and I got the following output:

[1]        NA        NA  9.957516 77.882353  6.993464 15.803922

I dont want the NA values to be shows in the output, how do I go about it?

This is my code:

columnmean <- function(x) {
                nc <- ncol(x)
                means <- numeric(nc)
                for(i in 1:nc) {
                                means[i] <- mean(x[, i])
                }
                means
}
Oct 31, 2018 in Data Analytics by Hannah
• 14,080 points
20 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Edit your code:

columnmean <- function(x, removeNA = TRUE) {
                nc <- ncol(x)
                means <- numeric(nc)
                for(i in 1:nc) {
                                means[i] <- mean(x[, i], na.rm = removeNA)
                }
                means
}
answered Oct 31, 2018 by Kalgi
• 35,800 points

Related Questions In Data Analytics

0 votes
2 answers

How to remove NA values from a Vector in R?

data = data[!is.na(data)]\ READ MORE

answered Apr 5 in Data Analytics by anonymous
3,546 views
0 votes
1 answer

How to remove HTML tags from string in R Programming?

Try this simple code to remove the <br ...READ MORE

answered Feb 1 in Data Analytics by Sophie may
• 9,050 points
60 views
0 votes
1 answer

How can I delete multiple values from a vector in R?

The %in% operator tells  which elements are ...READ MORE

answered Apr 26, 2018 in Data Analytics by shams
• 3,580 points
51 views
0 votes
1 answer

How to write a custom function which will replace all the missing values in a vector with the mean of values in R?

Consider this vector: a<-c(1,2,3,NA,4,5,NA,NA) Write the function to impute ...READ MORE

answered Jul 4, 2018 in Data Analytics by CodingByHeart77
• 3,680 points
54 views
0 votes
1 answer

How to sort a data frame by columns in R?

You can just use the order function ...READ MORE

answered Apr 10, 2018 in Data Analytics by darklord
• 6,140 points
54 views
0 votes
1 answer

How can I perform word stemming in R

The tm package in R provides the stemDocument() function to stem the ...READ MORE

answered Aug 20, 2018 in Data Analytics by ANMOL
• 3,620 points
35 views
0 votes
1 answer

How to know the type of an object?

To find the type of an object ...READ MORE

answered Sep 19, 2018 in Data Analytics by ANMOL
• 3,620 points
20 views
0 votes
1 answer

what causes these cannot open errors in R?

They are caused by attempts to read a ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 35,800 points
51 views
0 votes
1 answer

"no applicable method" Error in r programming

This is caused by using an object-oriented ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 35,800 points
30 views
0 votes
1 answer

": cannot open the connection" Error in R

There can be two reasons for this ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 35,800 points
205 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.