I would like to select specific rows in a dataframe when I get a value in some row. These selected lines (plus initial selected line) must compose a new dataframe and the dataframe name must be = $Name
in initial selected line.
The logic:
- The initial selected lines must have
$FC
=> 0.7. - The selected lines to form a dataframe must
$chr
= to initial selected line. - The selected lines must have
$Position
inside 5000 window (comparing with$Position
in initial selected line).
In this example, the line $Name
= BD22 cannot be included in BD13
dataframe because $Position
out of window number (5000 window to 3000 vary since $Position
= 500 until $Position
= 5500)
Follows above a simplified example:
My input input
dataframe:
Name FC chr Position
BD10 0.1 chr1 1000
BD11 0.1 chr2 1000
BD12 0.2 chr3 2000
BD13 0.7 chr3 3000
BD14 0.4 chr3 4000
BD22 0.1 chr3 7000
BD23 0.2 chr4 1000
I expect a dataframe with name line as output, in this example = BD13
:
Name FC chr Position
BD12 0.2 chr3 2000
BD13 0.7 chr3 3000
BD14 0.4 chr3 4000
After, I would like to plot each composed dataframe like this:
pdf(BD13.pdf)
plot(BD13$Name, BD13$FC, main="BD13",
xlab="Name", ylab="FC")
dev.off()
Thank you!
Can you rewrite what you mean in "3a"? It doesn't parse in English.
BTW, what have you tried so far? This is mostly just a matter of using
which()
and then subsetting the dataframe.I have tried:
But
Neigh1
andNeigh2
are empty...Just change the structure such that it iterates through out:
That way you needn't have a dataframe that changes names.
I didn't give you the entire solution, just the idea of a different way to structure things to get what you want. Literally just throwing that line in there wouldn't work, I'm expecting you to understand and apply the concept.