how do i divide table collumns in r

To divide a table's columns in R, you can use the mutate() function from the dplyr package. Here's an example:

main.r
# Load the dplyr package
library(dplyr)

# Create a sample data frame
df <- data.frame(a = 1:3, b = 4:6, c = 7:9)

# Divide column "a" by column "c"
df <- df %>% 
  mutate(new_column = a / c)

# View the updated data frame
df
226 chars
13 lines

In the above code, we create a sample data frame df with columns a, b and c. We then use mutate() to create a new column called new_column which is the result of dividing column a by column c. The %>% operator is used to "pipe" the df data frame into the mutate() function. Finally, we display the updated data frame.

gistlibby LogSnag