![](/img/trans.png)
[英]How to get names of cells in matrix (e.g., correlation matrix) which match a condition in R using row and column names for cell names?
[英]Pull out column names of cells which match logical criteria
我有一張這樣的桌子:
structure(list(Suggested.Symbol = c("CCT4", "DHRS2", "PMS2",
"FARSB", "RPL31", "ASNS"), p_onset = c(0.9378, 0.5983, 7.674e-10,
0.09781, 0.5495, 0.7841), p_dc14 = c(0.3975, 0.3707, 6.117e-17,
0.2975, 0.4443, 0.7661), p_tfc6 = c(0.2078, 0.896, 7.388e-19,
0.5896, 0.3043, 0.6696), p_tms30 = c(0.5724, 0.3409, 4.594e-13,
0.2403, 0.1357, 0.3422)), row.names = c(NA, 6L), class = "data.frame")
我想創建一個名為“摘要”的新列。 在其中,在逐行的基礎上,我想返回值 <0.05 的單元格的列名,逗號分隔。 那可能嗎??
我們可以通過遍歷行來使用toString
,創建一個值小於 0.05 的邏輯向量,將names
子集化並使用toString
粘貼它們
df1$summary <- apply(df1[-1], 1, \(x) toString(names(x)[x < 0.05]))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.