-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataFrame.cpp
More file actions
76 lines (63 loc) · 1.5 KB
/
DataFrame.cpp
File metadata and controls
76 lines (63 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <Rcpp.h>
using namespace Rcpp ;
// [[Rcpp::export]]
DataFrame FromSEXP( SEXP x){
DataFrame df(x) ;
return df;
}
// [[Rcpp::export]]
SEXP index_byName( DataFrame df, std::string s ){
return df[s];
}
// [[Rcpp::export]]
SEXP index_byPosition( DataFrame df, int i ){
return df[i];
}
// [[Rcpp::export]]
std::string string_element( DataFrame df ){
CharacterVector b = df[1];
std::string s;
s = b[1];
return s;
}
// [[Rcpp::export]]
DataFrame createOne(){
IntegerVector v = IntegerVector::create(1,2,3);
return DataFrame::create(Named("a")=v);
}
// [[Rcpp::export]]
DataFrame createTwo(){
IntegerVector v = IntegerVector::create(1,2,3);
std::vector<std::string> s = {"a", "b", "c" } ;
return DataFrame::create(Named("a")=v, Named("b")=s);
}
// [[Rcpp::export]]
DataFrame DataFrame_SlotProxy( S4 o, std::string yy ){
return DataFrame( slot(o, yy ) ) ;
}
// [[Rcpp::export]]
DataFrame DataFrame_AttributeProxy( List o, std::string y ){
return DataFrame( attr(o,y ) );
}
// [[Rcpp::export]]
int DataFrame_nrows( DataFrame df){
return df.nrows() ;
}
// [[Rcpp::export]]
DataFrame DataFrame_proxies( DataFrame df){
df[0] = seq(1, df.nrows() ) ;
df[1] = 3 ;
df["z"] = rep(2, 5) ;
df["x3"] = seq(1, df.nrows() ) ;
df["x4"] = 2.0 ;
return df ;
}
// [[Rcpp::export]]
CharacterVector df_rownames_get(DataFrame m){
return rownames(m) ;
}
// [[Rcpp::export]]
DataFrame df_rownames_set(DataFrame m){
rownames(m) = {"z","y","x","w","v"};
return m ;
}