Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 需要为列添加标签以除去NA列:NAs编号_Regex_R_File Handling_Na - Fatal编程技术网

Regex 需要为列添加标签以除去NA列:NAs编号

Regex 需要为列添加标签以除去NA列:NAs编号,regex,r,file-handling,na,Regex,R,File Handling,Na,我有两个文件,我必须链接在一起 > dim(sample.details) [1] 656 18 > dim(E.rna) [1] 47323 656 我的工作是将一个文件数据帧的列名与另一个文件数据帧的列中的值进行标记 ptr <- match( colnames(E.rna), sample.details$my_category_2 ) sample.details <- sample.details[ptr,] # reorde

我有两个文件,我必须链接在一起

   > dim(sample.details)
   [1] 656  18
   > dim(E.rna)
   [1] 47323   656
我的工作是将一个文件数据帧的列名与另一个文件数据帧的列中的值进行标记

 ptr <- match( colnames(E.rna), sample.details$my_category_2 )
 sample.details <- sample.details[ptr,] # reorder to correspond to rows of E.RNA
 rownames(E.rna)<-outcome

我不熟悉正则表达式。。。有什么建议吗?

我想您正在寻找以下正则表达式:

# build sample df
E.rna <- data.frame(U.95=1:5, HC.54=letters[6:10], NA.5=rnorm(5), KD.77=runif(5))

# get rid of unwanted variables
E.rna_conditions_cleaned <- E.rna[, grep("^NA", names(E.rna), invert=TRUE)]
#构建示例df

E.rna这可以通过使用
grepl
来实现,该模式匹配
NA
,后跟一个点(
),后跟列名上的一个或多个数字(
\\d+
),对逻辑输出求反,并使用它对列进行子集划分

E.rna_conditions_cleaned<-E.rna_conditions_cleaned[!grepl("^NA\\.\\d+",
          names(E.rna_conditions_cleaned))]

E.rna\u条件\u清洁你能展示一个小的可重复的例子和预期的输出吗?尝试
df[!grepl(^NA\\\\\d+”,names(df))]
子集中,您必须使用
select
来选择列,它可以是命名的或数字向量。您好,Akrun,您的意思是:“E.rna\u条件\u cleaned谢谢您Akrun我是用“E.rna\u条件\u cleaned”来选择的
# build sample df
E.rna <- data.frame(U.95=1:5, HC.54=letters[6:10], NA.5=rnorm(5), KD.77=runif(5))

# get rid of unwanted variables
E.rna_conditions_cleaned <- E.rna[, grep("^NA", names(E.rna), invert=TRUE)]
E.rna_conditions_cleaned<-E.rna_conditions_cleaned[!grepl("^NA\\.\\d+",
          names(E.rna_conditions_cleaned))]