Lists क्या हैं
एक list एक bag है जो किसी भी size की अलग-अलग तरह की चीज़ें hold कर सकता है, एक book, एक lunch, और एक ball वाले एक backpack की तरह। एक vector के उलट, इसके items match होने की ज़रूरत नहीं।
In this page:
Syntax
list_name <- list(name1 = value1, name2 = value2)
list_name$name1
list_name[["name2"]]
Lists
एक list अलग types और अलग lengths के elements एक साथ hold कर सकता है, एक vector के उलट जिसे uniform type चाहिए।
Elements double brackets से access होते हैं, list[[i]], खुद value पाने के लिए, जबकि single brackets, list[i], एक sub-list return करते हैं। Lists R का flexible general-purpose container हैं, दूसरी languages में एक struct या heterogeneous array जैसा।
Warning:
- list[1] पहला element रखने वाली एक list return करता है।
- list[[1]] खुद element return करता है -- इन्हें mix up करना एक बहुत common bug है।
उदाहरण: Lists
person <- list(name = "Alice", age = 30, active = TRUE)
print(person)
cat("Name:", person[["name"]], "\n")
cat("Name (dollar syntax):", person$name, "\n")
Login to try C/C++/Java/PHP code in the editor
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. #}
आम गलतियां
person["name"]इस्तेमाल करना और value की उम्मीद करना, जब single brackets एक list return करते हैं और[["name"]]या$nameelement return करते हैं।c()से values combine करना जब इनके अलग types हों, इसलिए येlist()में रहने की बजाय एक type में बदल जाते हैं।- यह मान लेना कि एक list को arithmetic में एक vector की तरह इस्तेमाल किया जा सकता है, जैसे
person + 1, जो एक error है।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: