I have a dataset containing 188k rows, having 4 columns. I was cleaning the dataset and i used skim for knowing how many missing values are there :
skim(Main_data)
It showed it has more than 50k missing values in each columns. So i treid to eliminate the rows containg empty cell, But I didn't geting the rows conating empty cell.
I tried many methods like this :
num_empty_val <- sum(Main_data1 == " ")
num_empty_val <- sum(is.na(Main_data1 ))
num_empty_val1 <- sum(complete.cases(Main_data1 ))
After trying all this it just giving m output that there is no empty cell, why?
I had just started to code in R, So please help me with this by suggesting some other ways i can do this.
If you want to eliminate all rows that have one or more columns with NA
reduced_data <- Main_data[complete.cases,]
by doing this it is showing a error
Error in xj[i] : invalid subscript type 'closure'
Without a reprex, I can't understand what's happening clearly. See the FAQ: How to do a minimal reproducible example reprex for beginners.
This error is something that can happen when using a function out of place. For example
xj <- LETTERS
xj[5]
#> [1] "E"
i <- function() pi
# this is the call of a function
i()
#> [1] 3.141593
# here is a "closure"
i
#> function() pi
xj[i]
#> Error in xj[i]: invalid subscript type 'closure'
# within the `for` function, i
# is no longer a closure, because
# it is being invoked in the .Local
# environment
for(i in 1:3) print(xj[i])
#> [1] "A"
#> [1] "B"
#> [1] "C"
Created on 2023-07-19 with reprex v2.0.2
Here's what I mean by using complete.cases
# the data frame has 32 rows
dim(mtcars)
#> [1] 32 11
# introduce a missing value in the first row
mtcars[1,1] <- NA
# subset by the rows with no missing values
# dimension now shows one fewer row
mtcars[complete.cases(mtcars),] |> dim()
#> [1] 31 11
It worked, Thanks for your time sir