vignettes/tutorial/xtractor_update_feature.Rmd
xtractor_update_feature.Rmd
Use case:
Click here on how to use the R6 class Xtractor
.
library(fxtract) xtractor = Xtractor$new("xtractor") xtractor$add_data(iris, group_by = "Species") fun1 = function(data) { c(mean_sepal_length = mean(data$Sepal.Length), sd_sepal_length = sd(data$Sepal.Length)) } fun2 = function(data) { c(mean_petal_length = mean(data$Petal.Length), sd_petal_length = sd(data$Petal.Length)) } xtractor$add_feature(fun1) xtractor$add_feature(fun2) xtractor$calc_features()
All features have been calculated:
xtractor$results
## Species mean_sepal_length sd_sepal_length mean_petal_length
## 1 setosa 5.006 0.3524897 1.462
## 2 versicolor 5.936 0.5161711 4.260
## 3 virginica 6.588 0.6358796 5.552
## sd_petal_length
## 1 0.1736640
## 2 0.4699110
## 3 0.5518947
Let’s say we want to edit our features to use the robust measures median()
and mad()
.
First we need to write the functions:
xtractor$remove_feature(fun1)
This deletes all calculated features corresponding to fun1
.
It’s also possible to pass a character string:
xtractor$remove_feature("fun2")
All there is left to do is to add the new feature functions and to execute the calculation process:
xtractor$add_feature(fun1_robust) xtractor$add_feature(fun2_robust)
xtractor$calc_features() xtractor$results
## Species median_sepal_length mad_sepal_length median_petal_length
## 1 setosa 5.0 0.29652 1.50
## 2 versicolor 5.9 0.51891 4.35
## 3 virginica 6.5 0.59304 5.55
## mad_petal_length
## 1 0.14826
## 2 0.51891
## 3 0.66717