शुरू करेंमुफ़्त में शुरू करें

Attributes

आप कोर्स के आखिरी अभ्यास तक पहुँच गए हैं! बधाई! चलिए इसे एक आसान से अभ्यास के साथ समाप्त करते हैं.

Attributes आपके डेटा स्ट्रक्चर के बारे में अतिरिक्त मेटाडेटा होते हैं. सबसे आम attributes हैं: row names और column names, dimensions, और class. आप attributes() फंक्शन का उपयोग करके उस ऑब्जेक्ट के attributes की सूची पा सकते हैं जिसे आप पास करते हैं. किसी खास attribute तक पहुँचने के लिए आप attr() फंक्शन का उपयोग कर सकते हैं.

cash के attributes देखते हुए:

attributes(cash)

$names
[1] "company"   "cash_flow" "year"     

$row.names
[1] 1 2 3 4 5 6 7

$class
[1] "data.frame"

attr(cash, which = "names")

[1] "company"   "cash_flow" "year"     

यह अभ्यास पाठ्यक्रम का हिस्सा है

R for Finance परिचय

पाठ्यक्रम देखें

अभ्यास निर्देश

  • आपके लिए matrix my_matrix और factor my_factor पहले से दिए गए हैं.
  • my_matrix पर attributes() का उपयोग करें.
  • my_matrix पर attr() का उपयोग करके "dim" attribute रिटर्न करें.
  • my_factor पर attributes() का उपयोग करें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# my_matrix and my_factor
my_matrix <- matrix(c(1,2,3,4,5,6), nrow = 2, ncol = 3)
rownames(my_matrix) <- c("Row1", "Row2")
colnames(my_matrix) <- c("Col1", "Col2", "Col3")

my_factor <- factor(c("A", "A", "B"), ordered = T, levels = c("A", "B"))

# attributes of my_matrix


# Just the dim attribute of my_matrix


# attributes of my_factor
कोड संपादित करें और चलाएँ