Why does this code also take downregulated values instead of just upregulated values?

DEG_data <- read.csv(file="DEG_changes(1).csv", header = TRUE)
concentrations <- DEG_data$concentration 
unique_concentration <- unique(DEG_data$concentration)
numDEGs <- DEG_data$numberDEGs
changeDEGs <- DEG_data$changeDEG


upregulated_indices <- which(changeDEGs == "upregulated")

upregulated_conc2nM <- numDEGs[upregulated_indices & concentrations == unique_concentration[1]]
upregulated_conc5nM <- numDEGs[upregulated_indices & concentrations == unique_concentration[2]]
upregulated_conc50nM <- numDEGs[upregulated_indices & concentrations == unique_concentration[3]]

I am trying to make a subset that contains just data from the “upregulated” part of the data column but it is also taking data from the column that is “downregulated”

  • Easier to help if you make this question reproducible by including a small representative dataset in a plain text format – for example the output from dput(DEG_data), if that is not too large.

    – 

  • Also I suspect using dplyr::filter on the original data frame would greatly simplify your code.

    – 




  • @neilfws the data is quite long but I can provide a snippet of what the data set looks like 2997 50 nM upregulated 7566 2998 50 nM upregulated 7569 2999 50 nM upregulated 7809 3000 50 nM upregulated 7626 3001 2 nM downregulated -1539 3002 2 nM downregulated -1323 3003 2 nM downregulated -1343 3004 2 nM downregulated -1543 3005 2 nM downregulated -1301 3006 2 nM downregulated -1447 3007 2 nM downregulated -1555

    – 




  • A small representative dataset will do, edit the question to include it.

    – 

  • this is a bad representation but the upregulated and down are all in one column as well as the nM vals and other values

    – 

Leave a Comment