仅从R中的特定数据集中提取行



我有一个表,它看起来像这样:

df1 <- data.frame(
"seqid" = c("12", "12", "13", "12", "12", "15"),
"source" = c("star", "star", "star", "star", "star", "star"), 
"type" = c("CDS", "CDS", "CDS", "intron", "CDS", "intron"),
"start" = c("15", "21", "23", "35", "45", "60"), 
"end" = c("70", "80", "86", "45", "67", "88"),
"attributes" = c("ENSOCUT00000011013", "ENSOCUT00000064484", 
"ENSOCUT00000013302", 
"ENSOCUT00000010968", "ENSOCUT00000010968", "ENSOCUT00000060283"),
stringsAsFactors = F,check.names=FALSE)
类型CDSENSOCUT00000011013[/tr>CDSENSOCUT00000064484CDSENSOCUT00000013302[/tr>内含子ENSOCUT00000010968CDS>ENSOCUT00000010968内含子>ENSOCUT00000060283
seqid开始结束属性
121570
122180
122386
12恒星3545
124567
12恒星88
df1[c(1,2,3,5),]

通常情况下,在数据的括号中选择编号的行/列。帧df:

df[rows_selected_go_here, columns_selected_go_here]

我假设您只需要来自df的那些条目,其中Type(字符串(等于CDS

library(tidyverse)
df <- mutate(df, TOBINCL= 0)
df$TOBINCL[grepl("^CDS$", df$Type, ignore.case = TRUE)] <- 1
mynewdf <- df[(df$TOBINCL==1) , ]

相关内容

  • 没有找到相关文章

最新更新