I have the following data.frame
gene that has more than 100 thousand values and they are found according to the total column between values of 221 and 213 (that is, there are values for: 213, 214, 215, 216, 217, 218, 219, 220 and 221)
mix total
1 A2M-ACTB 221
2 A2M-ACTG1 221
3 A2M-ANXA1 221
4 A2M-APP 221
5 A2M-B2M 221
6 A2M-CD24 221
7 A2M-CD74 221
8 A2M-COL1A2 221
9 A2M-COL3A1 221
10 A2M-DSP 221
11 A2M-EEF1A1 221
12 A2M-ENO1 221
13 A2M-FN1 221
14 A2M-GAPDH 221
15 A2M-HLA-B 221
16 A2M-HSP90AB1 221
17 A2M-MGP 221
18 A2M-RPL13A 221
19 A2M-RPS6 221
20 A2M-TM4SF1 221
And what I would like to do first is to count the number of rows of genes that have 221, then 220, and so on up to 213. Then I would like to separate each count into individual objects.
The function
tapply()
allows you to apply a function to the values of a variable according to the categories of another variable. In this case, the function we can apply to count the categories intotal
islength()
.Hello!
I give the data set as an example
iris
and then I indicate how it would be done with your data set.1) With the data set
iris
2) With your data (being
data
your name)In case you are a new user, I explain a little what each step does:
total
nrow()
the number of rows of that sub-matrix, that is, the number of genes that have the same value for the variabletotal
total
.If you dare to enter the mode
tidy
to work with the data, you will see that it is quite simple to elaborate what you ask for. Assuming an example similar to yours:The way to work is to apply step by step the transformations of the data that are necessary, in this case
total
from a previously defined settotal
As for separating each count into individual objects , I imagine you are talking about transforming each row into an element of a list, which you can do by applying the verb
group_split()
: