I know my next question es very basic in R, but I'm new on this! I have a data frame with qPCR information. What I want to do is a new column with the ct average as a function of spraying, genotype, and gene. This is my data frame, so you can understand what I mean:
> d
gene sampleCode genotype spraying ct mean.ct
1 1 1-C1-R1-SA a without 31.06 31.06
2 1 1-C1-R2-SA a without 30.71 31.06
3 1 1-C1-R3-SA a without 31.42 31.06
4 1 1-C1-R1-CA a with 31.78 31.98
5 1 1-C1-R2-CA a with 32.07 31.98
6 1 1-C1-R3-CA a with 32.08 31.98
7 1 2-C2-R1-SA b without 32.16 32.16
8 1 2-C2-R2-SA b without 32.52 32.16
9 1 2-C2-R3-SA b without 31.80 32.16
10 1 2-C2-R1-CA b with 32.55 32.28
11 1 2-C2-R2-CA b with 32.39 32.28
12 1 2-C2-R3-CA b with 31.91 32.28
13 2 1-C1-R1-SA a without 31.21 31.58
14 2 1-C1-R2-SA a without 31.96 31.58
15 2 1-C1-R3-SA a without 31.58 31.58
16 2 1-C1-R1-CA a with 32.75 32.75
17 2 1-C1-R2-CA a with 32.53 32.75
18 2 1-C1-R3-CA a with 32.98 32.75
19 2 2-C2-R1-SA b without 31.64 31.64
20 2 2-C2-R2-SA b without 32.83 31.64
21 2 2-C2-R3-SA b without 30.45 31.64
22 2 2-C2-R1-CA b with 31.97 32.43
23 2 2-C2-R2-CA b with 32.60 32.43
24 2 2-C2-R3-CA b with 32.72 32.43
I make the column "mean.ct" in excel, but I can´t make for all the rows because I have a lot of information! Does anyone know how I can make this new column in R with a simple code? I thought using the function "for" and "if". But I can´t realize how! Any help will be appreciated so much! Thanks!