← Back to R Course | Chapter 12: Best Practices | Lesson 4 of 6

is.na() को Handle करना

is.na हर value को missing होने के लिए check करता है, एक classroom में empty seats ढूंढने की तरह। आप इसे अपने data में blanks ढूंढने या skip करने के लिए इस्तेमाल कर सकते हैं।
Syntax
r
is.na(x)
x[!is.na(x)]
mean(x, na.rm = TRUE)

is.na() Handle करना

is.na(x) एक vector के हर element को missing values (NA) के लिए test करता है, एक logical vector return करते हुए।

Analysis से पहले data clean करने के लिए यह essential है, क्योंकि कई functions या तो NA propagate करते हैं या इसे ignore करने के लिए na.rm = TRUE चाहते हैं। sum(is.na(x)) एक common idiom है यह count करने के लिए कि एक vector में कितनी missing values हैं।

Warning:
  • missing values test करने के लिए कभी सीधे x == NA से compare न करें -- यह हमेशा NA return करता है, TRUE/FALSE नहीं।
  • इसकी बजाय is.na(x) इस्तेमाल करें।

उदाहरण: Handling is.na()

markup
values <- c(10, NA, 25, NA, 30)

print(is.na(values))
cat("Number of missing values:", sum(is.na(values)), "\n")

clean_values <- values[!is.na(values)]
print(clean_values)
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. x == NA से missing values test करना, जो हमेशा NA देता है; is.na(x) इस्तेमाल करें।
  2. यह भूल जाना कि NaN, is.na() में NA count होता है, लेकिन NA, NaN नहीं है।
  3. !is.na() से NA remove करना और result save करना भूल जाना, क्योंकि original unchanged रहता है।
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.