by Suf | Sep 4, 2022 | Programming, R, Tips
The easiest way to center a title using ggplot2 is to modify the plot.title component of the theme using element_text(hjust=0.5). For example, library(ggplot2) ggplot(data=mtcars, aes(x=mpg, y=wt)) + geom_point() + ggtitle(“Automobile Weight vs Miles per...
by Suf | Sep 3, 2022 | Programming, R, Tips
The easiest way to transpose a data frame is to use the transpose() function from the data.table library. For example, library(data.table) # get data data(“mtcars”) # transpose t_mtcars <- transpose(mtcars) # get row and colnames in order...
by Suf | Sep 1, 2022 | Programming, R, Tips
Using the rowwise function from dplyr in combination with the mutation function, you can apply a function to every row in a table. For example, data %>% rowwise() %>% # a, b, c are column names mutate(sum_val = sum(a, b, c)) This tutorial will go through how to use...
by Suf | Aug 29, 2022 | Programming, R, Tips
The easiest way to add a sequence of numbers as an index column is to use the nrow() function, for example, df$index <- 1:nrow(df) This tutorial will explain how to add a numeric ID column to a data frame with code examples. Table of contentsAdd Index Column to...
by Suf | Aug 26, 2022 | C++, Programming, Tips
This tutorial will go through how to iterate over the words of a string consisting of multiple words. Table of contentsIterate Over Words using istringstreamIterate Over Words using for-loopIterate Over Words using strtokIterate Over Words using Boost LibrarySummary...
by Suf | Aug 24, 2022 | C++, Programming, Tips
The simplest way to sum the elements of a vector is to use the accumulate function. This tutorial will describe the different ways to sum the elements of a vector with code examples. Table of contentsSum Elements of a Vector Using accumulateSum Elements of a Vector...