gge-ucd / Discussion

Class discussion for R-DAVIS course
0 stars 4 forks source link

Trying to manipulate data with tidyverse #36

Closed cadlam closed 6 years ago

cadlam commented 6 years ago

I am working on some data about plant response to a treatment, with paired plots. I want to create a new column (using mutate?), with the difference in the response variable between the two paired plots, treatment and control. I have one column specifying the number of the pair (1, 2, ..., etc.), and another specifying whether the plot is a treatment or a control. Each row is a separate plot. So in the new column, I want the difference between the value for plot 1/control minus the value for plot 1/treatment, and the same for plot 2, etc. How do I get R to match the plot number from two rows, then subtract the control and treatment if the plot numbers match?

For the sake of example, my data looks like this:

`plot_num <- c(1,1,2,2,3,3,4,4)

trt <- c('c','t','c','t','c','t','c','t')

resp <- c(2,3,1,2,4,6,4,5)

data.frame(plot_num, trt, resp)`

Thanks!

ryanpeek commented 6 years ago

@cadlam We're going to go over joins and joining data in a week or so. As this might be more suited for the Davis R Users group, let's chat about this in class or if you can make it to Monday 10-12pm (same place as class), I can try to help you out.