-1
Con   A   B   C    D
20.0000 0.7150  0.6014  0.5665  0.5954
10.0000 0.5245  0.5139  0.5119  0.7416
5.0000  0.4305  0.3585  0.3347  0.6231
2.5000  0.2941  0.2592  0.2189  0.4809
1.2500  0.2257  0.1990  0.1809  0.3375
0.6250  0.1638  0.1439  0.1460  0.2189
0.3125  0.1673  0.1372  0.1466  0.2011
0.0000  0.1565  0.1449  0.1634  0.1556

My data is like this. I need to take this. I need take the average value of A & B and C & D and need to create two new columns. Also, I need to take the SE for those as well. How can I calulate the averge and SE of A & B and C & D and plot them in the line graph against the concentration?

This is my first time I trying with R but I can't understand anything here like which code should I use. I hope get a direction from here.

Vinícius Félix
  • 8,448
  • 6
  • 16
  • 32

1 Answers1

0

You can use the {dplyr} package to work on pairs of data frame columns on a row-by-row basis to calculate the means and SEs that you requested. Then you can plot these values on a graph as two lines. A further enhancement would be to use pivot_longer() to create a long format version of the data making graphing even easier.

suppressPackageStartupMessages(library(tidyverse))

dat <- read.delim(sep="", text="
Con A B C D
20.0000 0.7150  0.6014  0.5665  0.5954
10.0000 0.5245  0.5139  0.5119  0.7416
5.0000  0.4305  0.3585  0.3347  0.6231
2.5000  0.2941  0.2592  0.2189  0.4809
1.2500  0.2257  0.1990  0.1809  0.3375
0.6250  0.1638  0.1439  0.1460  0.2189
0.3125  0.1673  0.1372  0.1466  0.2011
0.0000  0.1565  0.1449  0.1634  0.1556
")

dat %>% 
  rowwise() %>% 
  mutate(mAB = mean(c(A,B)),
         mCD = mean(c(C,D)),
         seAB = sd(c(A,B))/sqrt(length(c(A,B))),
         seCD = sd(c(C,D))/sqrt(length(c(C,D)))) -> result
result
#> # A tibble: 8 × 9
#> # Rowwise: 
#>      Con     A     B     C     D   mAB   mCD    seAB   seCD
#>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>   <dbl>  <dbl>
#> 1 20     0.715 0.601 0.566 0.595 0.658 0.581 0.0568  0.0145
#> 2 10     0.524 0.514 0.512 0.742 0.519 0.627 0.00530 0.115 
#> 3  5     0.430 0.358 0.335 0.623 0.394 0.479 0.036   0.144 
#> 4  2.5   0.294 0.259 0.219 0.481 0.277 0.350 0.0174  0.131 
#> 5  1.25  0.226 0.199 0.181 0.338 0.212 0.259 0.0134  0.0783
#> 6  0.625 0.164 0.144 0.146 0.219 0.154 0.182 0.00995 0.0365
#> 7  0.312 0.167 0.137 0.147 0.201 0.152 0.174 0.0151  0.0272
#> 8  0     0.156 0.145 0.163 0.156 0.151 0.159 0.0058  0.0039

ggplot(result) +
  aes(x=Con, y=mAB) + 
  geom_point() +
  geom_line() +
  geom_point(aes(x=Con, y=mCD), shape=2) +
  geom_line(aes(x=Con, y=mCD), linetype=2)

Created on 2023-06-26 with reprex v2.0.2

DavoOZ
  • 41
  • 3
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 28 '23 at 19:26