in Education by
I have a huge vector which has a couple of NA values, and I'm trying to find the max value in that vector (the vector is all numbers), but I can't do this because of the NA values. How can I remove the NA values so that I can compute the max? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
To remove NA’s from a vector use the following code: Vec <- Vec[!is.na(Vec)] For example: Vec <- c(1, 100, NA, 10,NA,5,6,7,8,9,4,3,5,NA) Vec <- Vec[!is.na(Vec)] Vec [1] 1 100 10 5 6 7 8 9 4 3 5 You can also use the na.rm argument inside the max function to find the maximum number. For example: Vec <- c(1, 100, NA, 10,NA,5,6,7,8,9,4,3,5,NA) max(Vec, na.rm = TRUE) Output: [1] 100 If you want to explore more in R programming then watch this R programming tutorial for beginner:

Related questions

0 votes
    I have a vector of numbers: numbers...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I'm trying to create two dimensional std::vector, that will hold objects of this class I inherited. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 27, 2022 in Education by JackTerrance
0 votes
    How can I check if a given value is contained in a vector? Select the correct answer from above options...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    I have a list and I want to remove a single element from it. How can I do this? I've tried looking ... 't found anything appropriate. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I'm trying to keep the legend of one layer (smooth) and remove the legend of the other (point). I have tried ... = gear)) + theme_bw() Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    Many times I have seen the set.seed function in R, before starting the program. I know it's basically used for ... need to set this? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    How do you import a plain text file as a single character string in R? I think that this will probably ... is probably unstable too. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    The install.packages() function in R is the automatic unzipping utility that gets and install packages in R. ... accesses packages? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have code that at one place ends up with a list of data frames which I really want to convert ... starting with (this is grossly simplified for illustration): listOfDataFrames...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have a data frame with a column of p-values and I want to make a selection on these p-values. > pvalues_anova ... 7.125751e-01 5.193604e-01 4.835312e-04 Selection way: anovatest...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    A very newbish question, but say I have data like this: test_data...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    Suppose I have a ggplot with more than one legend. mov...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    Let's say that I have a date in R and it's formatted as follows. date 2012-02-01 2012-02-01 2012-02- ... generate the day by the date. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    Hi this simple code (and all my scripts from this morning) has started giving me an off-center title in ggplot2 Ubuntu ... the above this morning to try and fix this.... dat...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    A categorical variable V1 in a data frame D1 can have values represented by the letters from A to Z. I want to create a ... B','N',T')) Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
...