What are the steps to execute addition and total values count on a dataframe in R?
add a comment
Here are the steps to execute addition and total values count on a dataframe in R:
dplyr
or tidyverse
.library(dplyr)
df <- data.frame(x = c(1,2,3,4,5), y = c(6,7,8,9,10))
mutate
function to add a new column to the data frame, which is the sum of the existing columns.df <- df %>% mutate(z = x + y)
summarize
function to calculate the total value count of a specific column.df_total <- df %>% summarize(total_x = sum(x))
print(df)
print(df_total)
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-08 08:41:23 +0000
Seen: 7 times
Last updated: May 08 '23