Hi,
How do I subtract one column of data from another (Sample_778981
is my comparator), and save the result in a new *.csv file. I would like to obtain the difference of each sample with Sample_778981. I have tried with one comparison (see below). Similarly, I am interested to perform on all samples at the same time and save a csv file.
Data_Input <- read.csv(file ="./Data_Input.csv", stringsAsFactors = F, check.names = F, row.names = 1)
library(dplyr)
(Data_Sample_778981_vs_Sample_778951 <- Data_Input %>%
mutate(Diff_778981_vs_778951 = Sample_778951-Sample_778981))
Input data
dput(Data_Input)
structure(list(Sample_778981 = c(0L, 184L, 60L, 0L, 7L, 0L, 87L,
0L, 0L, 21L, 193L, 29L, 0L, 0L, 3L, 50L, 0L, 325L, 442L), Sample_778951 = c(0,
140.5, 64, 0, 4, 0, 83, 0, 1, 51.5, 199, 25, 0, 0, 5, 62, 0,
525, 407), Sample_778961 = c(0, 169, 45, 1, 3, 0, 122, 0, 0,
36.5, 179, 20, 0, 0, 1, 58, 0, 494, 570), Sample_778971 = c(0L,
107L, 67L, 0L, 5L, 0L, 99L, 0L, 0L, 63L, 178L, 34L, 0L, 0L, 2L,
60L, 0L, 467L, 283L), Sample_778991 = c(0L, 221L, 44L, 0L, 1L,
0L, 139L, 0L, 0L, 48L, 222L, 24L, 1L, 0L, 5L, 67L, 0L, 612L,
451L), Sample_779001 = c(0, 120.5, 45, 1, 1, 0, 100, 0, 0, 44.5,
202, 39, 1, 0, 3, 76, 0, 719, 681)), class = "data.frame", row.names = c("Gene_1",
"Gene_2", "Gene_3", "Gene_4", "Gene_5", "Gene_6", "Gene_7", "Gene_8",
"Gene_9", "Gene_10", "Gene_11", "Gene_12", "Gene_13", "Gene_14",
"Gene_15", "Gene_16", "Gene_17", "Gene_18", "Gene_19"))
Expected output
dput(Data_Output)
structure(list(Diff_778981_vs_778981 = c(0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Diff_778981_vs_778951 = c(0,
-43.5, 4, 0, -3, 0, -4, 0, 1, 30.5, 6, -4, 0, 0, 2, 12, 0, 200,
-35), Diff_778981_vs_778961 = c(0, -15, -15, 1, -4, 0, 35, 0,
0, 15.5, -14, -9, 0, 0, -2, 8, 0, 169, 128), Diff_778981_vs_778971 = c(0L,
-77L, 7L, 0L, -2L, 0L, 12L, 0L, 0L, 42L, -15L, 5L, 0L, 0L, -1L,
10L, 0L, 142L, -159L), Diff_778981_vs_778991 = c(0L, 37L, -16L,
0L, -6L, 0L, 52L, 0L, 0L, 27L, 29L, -5L, 1L, 0L, 2L, 17L, 0L,
287L, 9L), Diff_778981_vs_779001 = c(0, -63.5, -15, 1, -6, 0,
13, 0, 0, 23.5, 9, 10, 1, 0, 0, 26, 0, 394, 239)), class = "data.frame", row.names = c("Gene_1",
"Gene_2", "Gene_3", "Gene_4", "Gene_5", "Gene_6", "Gene_7", "Gene_8",
"Gene_9", "Gene_10", "Gene_11", "Gene_12", "Gene_13", "Gene_14",
"Gene_15", "Gene_16", "Gene_17", "Gene_18", "Gene_19"))
Thank you,
Toufiq