How to remove rows with NA content?

Good Morning,

I am trying to clean out of spss file rows with NA content. Then, I will be conducting glm(data,family=binary(logit)) .

data <- read_spss("data.save")
glm(q8_lesson_10~q8_lesson_1,family=binary(logit), data=data) .

Can anyone help me with why is not working?

If ou want to drop rows that have an NA value, you can use the drop_na function from the tidyr package.

DF <- data.frame(A=c(1,NA,3,4,5),
                  B=c(1,2,3,NA,5),
                  C=c(1,2,NA,4,5))
DF
   A  B  C
1  1  1  1
2 NA  2  2
3  3  3 NA
4  4 NA  4
5  5  5  5
library(tidyr)
DFclean <- drop_na(DF)
DFclean
  A B C
1 1 1 1
2 5 5 5
1 Like

Thanks for this information. I also have another data set, including survey collected data, that has values that needs to be removed, such as 8 and 9. These are empty and do not contribute any statistical information. How do I remove the rows with 8, 9, 98, and 99?

Try something like this.

DF <- data.frame(A=c(189,8,3,4,5),
                  B=c(1,2,3,9,5),
                  C=c(1,2,89,4,5))
DF
    A B  C
1 189 1  1
2   8 2  2
3   3 3 89
4   4 9  4
5   5 5  5
library(dplyr)
library(stringr)
DFclean <-  DF |> rowwise() |> 
   mutate(Flag = any(str_detect(c_across(), "^8$|^9$|^89$|^99$"))) |> 
   filter(!Flag)
DFclean
# A tibble: 2 x 4
# Rowwise: 
      A     B     C Flag 
  <dbl> <dbl> <dbl> <lgl>
1   189     1     1 FALSE
2     5     5     5 FALSE

It is working now. I have to conduct a logit test and summary.

I have an ordinal DV on my dataset. I want to conduct descriptive analysis between IV and DV. I have tried using:

data<- glm(DV~IV, data=data, family=binomial)
summary(data)
but it returns the wrong p value, like everything is 1.

I read online that it requires a ordered logit. Can you please provide an example? Thanks

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.