【问题标题】:Retrieve columns based on specific row with values that match a substring根据具有与子字符串匹配的值的特定行检索列
【发布时间】:2023-02-22 04:24:54
【问题描述】:

我想检索 subtype 行的值以“1”开头的列。

library(data.table)
df.1 <- df[df["subtype",] %like% "1",]

数据:

> dput(df[1:10,1:10])
structure(list(TCGA.2Z.A9J1.01A = c("1a", "5.13553076559331", 
"5.25437106109279", "0", "6.94770472476424", "0", "12.413916703553", 
"11.192440344074", "3.1585955515009", "0"), TCGA.2Z.A9J3.01A = c("2a", 
"4.75608390849743", "3.47688712558277", "3.69415587836022", "7.55464180068354", 
"0", "10.1701864662239", "9.9698319970815", "5.3250949389428", 
"0"), TCGA.2Z.A9J6.01A = c("2b", "5.17761487414502", "6.65033806253549", 
"0.584770128557275", "6.94039112615504", "0", "12.0370627256659", 
"10.8210532515207", "5.53845435576078", "0"), TCGA.2Z.A9J8.01A = c("1b", 
"3.73015082384196", "5.42861476811507", "0", "7.92705080275384", 
"0.41565051441473", "11.9979504885468", "9.91529337032864", "5.14529839229733", 
"0"), TCGA.2Z.A9JD.01A = c("2a", "3.30975827142464", "4.33563331445214", 
"0", "8.67290934153811", "0", "10.9513709097776", "10.8023152138843", 
"1.84534953815009", "0"), TCGA.2Z.A9JG.01A = c("2c", "7.28850529763777", 
"3.84460660023553", "3.00626211318484", "5.81778440061722", "0", 
"12.0868373610296", "10.3281796591297", "3.6562103201826", "0"
), TCGA.2Z.A9JJ.01A = c("1c", "6.28339584818368", "0.807272479985472", 
"4.53120676686483", "6.40832124805635", "0", "12.8200019062179", 
"11.792050825269", "2.35741124701605", "0"), TCGA.2Z.A9JL.01A = c("1c", 
"7.03644948442735", "3.73611776175452", "1.34522603534256", "6.5525507570889", 
"0.597983993789946", "12.9645888051835", "11.0094140803487", 
"7.40469964993127", "0"), TCGA.2Z.A9JN.01A = c("1b", "4.17567628766862", 
"0", "0", "7.2921559549592", "0", "12.2914311784018", "10.8173916627083", 
"0.514097004894233", "0"), TCGA.2Z.A9JP.01A = c("1d", "6.3033314339384", 
"1.11789447981141", "1.74010724619747", "7.46591652705797", "0", 
"13.3435017632051", "11.2086677724798", "1.74010724619747", "0"
)), row.names = c("subtype", "A1BG", "A1CF", "A2BP1", "A2LD1", 
"A2ML1", "A2M", "A4GALT", "A4GNT", "AAA1"), class = "data.frame")

【问题讨论】:

  • 您的代码中有什么问题。?要不要df[,df["subtype",] %like% "1"]
  • 我认为您交换了行/列索引。好像你的意思是df.1 &lt;- df[,df["subtype",] %like% "1"]

标签: r


【解决方案1】:

我们可能需要使用逻辑索引作为列索引而不是行索引

df[,df["subtype",] %like% "1"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-02
    • 2017-01-15
    • 2011-10-02
    • 2021-02-23
    • 1970-01-01
    • 2023-01-20
    • 1970-01-01
    相关资源
    最近更新 更多