how to summarise data but keep columns R

To summarize data while keeping columns in R, you can use the "aggregate" function. The first step is to define the data frame you want to summarize. Then, you can use the aggregate function with the formula interface, specifying the columns to be summarized and the function to be applied to each column. Finally, you can use the "data" argument to specify the data frame and the "by" argument to indicate the grouping variable. This will produce a new data frame with the summarized data while preserving the original columns.