diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index bd033e9..c0946a0 --- a/.gitignore +++ b/.gitignore @@ -95,4 +95,13 @@ flycheck_*.el # network security /network-security.data +# html files +*.html +# images +*.png +*.jpg +*.jpeg + +# pdf +*.pdf diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.org b/README.org old mode 100644 new mode 100755 index 5ab650f..7007590 --- a/README.org +++ b/README.org @@ -1,3 +1,14 @@ -# intro_r +* A brief introduction to R -Scripts describing simple tasks to learn the first steps to work with data using R programming environment \ No newline at end of file +Scripts describing simple tasks to learn the first steps to work with +data using the R programming environment + +** First steps in R + + * [[./script/help_r.R][Asking for help to use R]] + * [[./script/integerq_modulo.R][Integer quocient and modulo]] + * [[./script/non_stand_eval.R][Non-standard evaluation in R]] + +** Subsetting and indexing + + * [[./script/replace_values.R][Build column in table indexing values]] diff --git a/script/replace_values.R b/script/replace_values.R old mode 100644 new mode 100755 index 997bb22..879084b --- a/script/replace_values.R +++ b/script/replace_values.R @@ -71,9 +71,9 @@ maior_valor <- function (df, a, b, c, ...) { linhas <- nrow(df) coluna <- rep(0, times = linhas) - coluna[a_maior] <- "a" - coluna[b_maior] <- "b" - coluna[c_maior] <- "c" + coluna[a_maior] <- names(df)[[1]] + coluna[b_maior] <- names(df)[[2]] + coluna[c_maior] <- names(df)[[3]] df$V1 <- coluna @@ -103,3 +103,19 @@ dfd %>% m == 3 ~ names(.)[3], TRUE ~ as.character(m) )) + +#' ## Usando o pacote "datatable" + +library(data.table) + +class(df) + +dt <- setDT(df) + +#' Using "apply" to know the greatest value by each row ("1") across +#' columns +dt[, great := apply(df, 1, which.max) + ][, great := as.character(great) + ][, great := c("1" = "a", + "2" = "b", + "3" = "c")[great]]