Hi all, I have a question regarding subsetting a data frame based on a threshold value between different sets of columns and I am finding this surprisingly difficult to achieve. I would really appreciate some help!
Ultimately, the question is as follows: given a dataframe of (for example two columns), can i subset the data frame if the value in a row goes from a certain threshold in one column to another.
1 2
2 3
4 4
5 4
6 6
the result of the column above if i specified a threshold change of 1 would be:
rows 1,2 and 4:
1 2
2 3
5 4
Note that I specify the threshold to be a change between values of columns of 1. That means it could go up by 1 but also down by 1 (as above). I need the threshold to be specified like this if possible as i need to subset the changes in either direction... I am really struggling to figure out the code for this. I have an r object of genomic data. its a matrix of around 30 columns and many thousand rows. the columns are grouped in to conditions.. in this example two conditions, so 15 columns could be condition 1, and 15 columns could be condition 2.
I would like to know how count values change from condition 1 to 2 based on a threshold as above. The code i have so far is:
#Create rownames of individual groups samples = rownames(rObject@colData)[mSetSqFlt@colData[, "condition1"]== 1] samplesOne=rownames(rObject@colData)[mSetSqFlt@colData[, "condition2"]== 0]
I can then specify from the counts data which group of columns belongs to condition1 and which to condition2. This then splits my counts data as follows:
counts[samples,]
counts[samplesOne,]
Now what i would like to do is say either in all samples per group, identify rows that change from samples to sampleOne by a a threshold of counts (0.3 for example as they are scaled): so counts[samples,] > counts [samples2,] = 0.3 and then the output is a data frame where all counts from samples increase or decrease in value to sampleOne by at least 0.3.
Alternatively i would also like to explore the same thing but instead of all samples in each group, it could be, at least 4 samples from group 1 and 4 samples from group 2 have to have a threshold change.
i hope this makes sense and any help is much appreciated.
thanks!