code: def nth_kday(n, k, gyear, gmonth, gday):
      r"""Calculate the nth-kday in RDate format.
  
      Parameters
      ----------
      n : int
          Occurrence of a given day counting in either direction.
      k : int
          Day of the week.
      gyear : int
          Gregorian year.
      gmonth : int
          Gregorian month.
      gday : int
          Gregorian day.
  
      Returns
      -------
      nthkday : int
          nth-kday in RDate format.
      """
  
      rdate = gdate_to_rdate(gyear, gmonth, gday)
      if n > 0:
          nthkday = 7 * n + kday_before(rdate, k)
      else:
          nthkday = 7 * n + kday_after(rdate, k)
      return nthkday
  
imports: import calendar
  import logging
  import math
  import pandas
label_desc: Use image node_id 21 for calling a global function with example usage: nth_kday(n, k, gyear, gmonth, gday) and returns: nthkday