`.SD` का उपयोग कर j में गणनाएँ

R में data.table के साथ Data Manipulation

Matt Dowle, Arun Srinivasan

Instructors, DataCamp

Subset of Data, .SD

  • .SD एक खास सिंबल है, जिसका मतलब है Subset of Data
  • हर ग्रुप के अनुरूप डेटा का सबसेट रखता है; जो खुद एक data.table होता है
  • सुविधा के लिए डिफॉल्ट रूप से ग्रुपिंग कॉलम शामिल नहीं होते
x <- data.table(id = c(1, 1 ,2, 2, 1, 1), 
                val1 = 1:6, val2 = letters[6:1])
id val1 val2
 1    1    f
 1    2    e
 2    3    d
 2    4    c
 1    5    b
 1    6    a
R में data.table के साथ Data Manipulation

Subset of Data, .SD

x[, print(.SD), by = id]
val1 val2
   1    f
   2    e
   5    b
   6    a
val1 val2
   3    d
   4    c
Empty data.table (0 rows) of 1 col: id
R में data.table के साथ Data Manipulation

Subset of Data, .SD

x[, .SD[1], by = id]
id val1 val2
 1    1    f
 2    3    d
R में data.table के साथ Data Manipulation

Subset of Data, .SD

x[, .SD[.N], by = id]
id val1 val2
 1    6    a
 2    4    c
R में data.table के साथ Data Manipulation

.SDcols

.SDcols उन कॉलमों को रखता है जो .SD में होने चाहिए

batrips[, .SD[1], by = start_station]
           start_station   trip_id   duration            start_date  
 San Francisco City Hall    139545        435   2014-01-01 00:14:00  
  Embarcadero at Sansome    139547       1523   2014-01-01 00:17:00
# .SDcols नियंत्रित करता है कि .SD में कौन-से कॉलम हों
batrips[, .SD[1], by = start_station, .SDcols = c("trip_id", "duration")]
          start_station   trip_id   duration
San Francisco City Hall    139545        435
 Embarcadero at Sansome    139547       1523
R में data.table के साथ Data Manipulation

.SDcols

batrips[, .SD[1], by = start_station, .SDcols = - c("trip_id", "duration")]
           start_station             start_date           
 San Francisco City Hall    2014-01-01 00:14:00  
  Embarcadero at Sansome    2014-01-01 00:17:00  
R में data.table के साथ Data Manipulation

अभ्यास करते हैं!

R में data.table के साथ Data Manipulation

Preparing Video For Download...