Foldable ऑपरेशंस (I)
ऐसा ऑपरेशन जो वही उत्तर देता है, चाहे आप उसे पूरे डेटासेट पर लगाएँ या डेटासेट के chunks पर लगाकर बाद में उनके परिणामों को मिलाएँ — उसे कभी-कभी foldable कहा जाता है। max() और min() इसके उदाहरण हैं.
यहाँ, हमने range() फंक्शन का एक foldable संस्करण परिभाषित किया है जो या तो एक vector लेता है या vectors की list.
मॉर्टगेज डेटासेट पर इसे टेस्ट करके जाँचें कि यह फंक्शन सही काम करता है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
R में Scalable Data Processing
अभ्यास निर्देश
- यह जाँचें कि
foldable_range()mortडेटासेट के"record_number"कॉलम पर काम करता है.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
foldable_range <- function(x) {
if (is.list(x)) {
# If x is a list then reduce it by the min and max of each element in the list
c(Reduce(min, x), Reduce(max, x))
} else {
# Otherwise, assume it's a vector and find its range
range(x)
}
}
# Verify that foldable_range() works on the record_number column
___