Skip to content

Instantly share code, notes, and snippets.

@ifknot
Created October 17, 2020 15:53
Show Gist options
  • Save ifknot/d6fb86c11af2493235460b76e9aacf65 to your computer and use it in GitHub Desktop.
Save ifknot/d6fb86c11af2493235460b76e9aacf65 to your computer and use it in GitHub Desktop.
r-ish head
#include "head.h"
namespace R {
variant_vector head(const variant_vector& x, size_t n) {
return variant_vector (x.begin(), (x.size() < n) ? x.end() : x.begin() + 6);
}
data_frame head(const data_frame& x, size_t n) {
data_frame df;
for (const auto& [key, vctr] : x) { // keys as column headings
df[key] = head(vctr, n);
}
return df;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment