首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏用户7627119的专栏

    R替换函数gsub

    gsub(pattern, replacement, x, ignore.case = FALSE, perl = FALSE, fixed = FALSE, useBytes = FALSE string举例如下: > gsub("ut","ot",x) ignore.case表示是否忽视大小写。 vector举例如下: > x <- c("R Tutorial","PHP Tutorial", "HTML Tutorial") > gsub("Tutorial","Examples",x) #将 > x <- "line 4322: He is now 25 years old, and weights 130lbs" > y <- gsub("\\d+","---",x) #\\d表示一个任意的数字 years old, and weights ---lbs" > x<- "line 4322: He is now 25 years old, and weights 130lbs" > y <- gsub

    1.9K10发布于 2020-08-06
  • 来自专栏nginx遇上redis

    Lua string.gsub (1)

    Lua中的模式匹配用正则表达式来描述,它被用于string.find, string.gmatch,string.gsub, 和string.match.匹配一种模式。

    1.1K20发布于 2021-01-06
  • 来自专栏全栈程序员必看

    awk 字符串替换 gsub

    gsub(r,s) 在整个$0中用s替代r gsub(r,s,t) 在整个t中用s替代r awk -F “,” ‘{str=gsub(/\t*| *$/,””,$3); ret=$1″,”$2″,”$3″,”NR;print ret}’ 去除第三个字段的空格与制表符 awk -F “\t” ‘{if($3==”吉林”) {gsub($3,”吉林省”,$3);print 白山 吉林省 229999 吉林其它 吉林省 对排好序的各个端数据取前1000 sort -t , -k3,3 -k4,4nr file | awk -F “,” ‘{str=gsub

    3.2K20编辑于 2022-09-14
  • 来自专栏用户7627119的专栏

    R中的替换函数gsub

    R中gsub替换函数的参数如下 gsub(pattern, replacement, x, ignore.case = FALSE, perl = FALSE, fixed = FALSE, string举例如下: > gsub("ut","ot",x) ignore.case表示是否忽视大小写。 #将Stage III和Stage IV替换成stage III/IV stage=gsub("Stage IV. *","stage III/IV",stage) stage=gsub("Stage III. *","stage III/IV",stage) stage=gsub("Stage III.

    5.3K20编辑于 2022-09-21
  • 来自专栏用户7627119的专栏

    【R语言】因子在临床分组中的应用

    函数 前面也给大家介绍过☞R替换函数gsub #删除组织病理学分期末尾的A,B或者C等字母,例如Stage IIIA,Stage IIIB stage=gsub("[ABCD]$","",clin$ajcc_pathologic_stage ) #将Stage III和Stage IV替换成stage III/IV stage=gsub("Stage IV. *","stage III/IV",stage) stage=gsub("Stage III. =gsub("Stage IV. *","stage III/IV",stage) stage=gsub("Stage III.

    5.1K21编辑于 2022-09-21
  • 来自专栏游戏开发之旅

    Lua中正则表达式的使用整理

    " print(string.gsub(str, "%d", "6")) -- ab6c6d 2 print(string.gsub(str, "%D", "6")) -- 661626 4 -- %l str = "AbA12Bc3" print(string.gsub(str, "%l", "G")) -- AGA12BG3 2 print(string.gsub(str, "%L 1 print(string.gsub(str, "%S", ",")) -- ,,,,, ,,,,,, 11 -- %u str = "AbA12Bc3" print(string.gsub(str (string.gsub(str, "%w", "厉害")) -- 中文很厉害厉害 2 print(string.gsub(str, "%W", "厉害")) -- 厉害厉害厉害厉害厉害厉害厉害厉害厉害 6a 9 -- %x str = "MN1GeF" print(string.gsub(str, "%x", "o")) -- MNoGoo 3 print(string.gsub(str

    15.7K30发布于 2019-12-02
  • 来自专栏首富手记

    每日一题--2-求一个文件里面指定字符出现的次数

    我们使用/ect/passwd文件来模拟,我们取出文件中:出现的次数 [root@web01-7 /]# cp /etc/passwd /tmp/ [root@web01-7 /]# awk '{Num=gsub ,我们可以使用这个来来文件中的":"替换成":"然后让他返回替换了多少次,我们就能统计出来出现了多少次 2,第二个里程碑 了解gsub的语法格式: 替换:gsub(/要替换的字符串/,"替换成的字符串" ,在哪个地方替换) 替换的次数:Num = gsub(/要替换的字符串/,"替换成的字符串",在哪个地方替换) 3,第三个里程碑 了解了上面两个我们就能完整上述的那个表达式了,为什么要在最后面输出END 因为我们对sum进行了累加,再有在末行模式才能统计出来出现的所有次数 4,优化上述表达式 [root@web01-7 /]# awk '{sum = sum + gsub(/:/,"",$0)}END{ print sum}' /tmp/passwd 156 总结 1,awk中的gsub替换所有的符合的字符串,相当于sed的“s###g” 2,awk中的sub只替换第一次匹配的字符串,相当于sed的

    60710发布于 2018-10-09
  • 来自专栏优雅R

    「R」Rprofile:R 全局设置

    xfun::file_ext .rm_ext <- xfun::sans_ext .ch_ext <- xfun::with_ext ## Provide the "file" version of gsub (), ## i.e., they perform searching and replacement in files via gsub(). .gsub_file <- xfun::gsub_file .gsub_files <- xfun::gsub_files .gsub_dir <- xfun::gsub_dir .gsub_ext <- xfun::gsub_ext ## Change the

    1.9K21发布于 2020-08-14
  • 来自专栏sunsky

    Lua模式匹配

    string.gsub("hello Lua", "(%w+)%s*(%w+)", "%2 %1")) Lua hello 1 > string.gsub("hello world", "%w+ (str, sourcestr, desstr) string.gsub的基本作用是用来查找匹配模式的串,并将使用替换串其替换掉: string.gsub函数有三个参数:目标串,模式串,替换串。 s = string.gsub("Lua is cute", "cute", "great") print(s) --> Lua is great s = string.gsub("all --> axl lii s = string.gsub("all lii", "l", "x", 2) print(s) --> axx lii string.gsub的第二个返回值表示他进行替换操作的次数 例如, %S表示与任何非空白字符配对.例如,'%A'非字母的字符 print(string.gsub("hello, up-down!"

    2.4K30发布于 2020-08-20
  • 来自专栏tea9的博客

    jekyll添加文章流程

    (CONFIG['posts']) title = ENV["title"] || "new-post" slug = title.downcase.strip.gsub(' ', '-').gsub filename, 'w') do |post| post.puts "---" post.puts "layout: post" post.puts "title: \"#{title.gsub (CONFIG['drafts']) title = ENV["title"] || "new-post" slug = title.downcase.strip.gsub(' ', '-'). gsub(/[^\w-]/, '') filename = File.join(CONFIG['drafts'], "#{Time.now.strftime('%Y-%m-%d')}-#{slug} filename, 'w') do |post| post.puts "---" post.puts "layout: post" post.puts "title: \"#{title.gsub

    71020编辑于 2022-07-16
  • 来自专栏拓端tecdat

    R语言对耐克NIKEID新浪微博数据K均值(K-MEANS)聚类文本挖掘和词云可视化

    =" "]; 剔除通用标题 res=gsub(pattern="NIKEiD"," ",res); res=gsub(pattern="http://t.cn/"," ",res); res =gsub(pattern="com"," ",res); res=gsub(pattern="耐克"," ",res); res=gsub(pattern="官网"," ",res); res= gsub(pattern="中国"," ",res); 分词+频数统计 keyword=lapply(X=res, FUN=segmentCN) words=unlist(keyword); 绘制词汇图

    56200编辑于 2022-12-27
  • 来自专栏菜鸟学数据分析之R语言

    文本挖掘|你好,正则表达式!

    (com|cn)' > gsub(pattern,'*',eg) [1] "*" "add@piilgu" "*" "*" pattern正则表达式含义为:大小写字母或数字 1、匹配数字 > x<-' Ta说群众笑脸smile是最好的扶贫成绩单1234 ' > gsub('[0-9]','*',x) [1] " Ta说群众笑脸smile是最好的扶贫成绩单**** " 2、匹配英文 [A-z]”匹配大小写英文,“[A-Z]”匹配大写英文,“[a-z]”匹配小写英文 > x<-' Ta说群众笑脸smile是最好的扶贫成绩单1234 ' > gsub('[a-z]','*',x) [ " T*说群众笑脸*****是最好的扶贫成绩单1234 " 3、匹配汉字 “[\u4E00-\u9FA5]”机械匹配汉字 > x<-' Ta说群众笑脸smile是最好的扶贫成绩单1234 ' > gsub ,'*',x) [1] " T************************ " 6、“非”的使用 以“^”符号表示“非” > x<-' Ta说群众笑脸smile是最好的扶贫成绩单1234 ' > gsub

    86431发布于 2020-08-05
  • 来自专栏用户7627119的专栏

    【R语言】临床特征分组,多分类转换成二分类

    根据T分期的定义,T1和T2期的肿瘤大小相对较小,所以用gsub将T1和T2替换成small,将T3和T4替换成big。这样我们就有两个组了,便于后面做差异表达分析。 T=clinical$ajcc_pathologic_t T=gsub("T1.*","small",T) T=gsub("T2.*","small",T) T=gsub("T3. *","big",T) T=gsub("T4. stage=clinical$ajcc_pathologic_stage stage=gsub("Stage IV. *","advanced",stage) stage=gsub("Stage III.*","advanced",stage) stage=gsub("Stage.

    76410编辑于 2022-09-21
  • 来自专栏小明的数据分析笔记本

    R语言数据分析有意思的小例子:Prince的歌词挖掘 — 1

    ()函数替换掉歌词文本的一些像won't can't等内容 fix.contractions<-function(doc){ doc <- gsub("won't","will not",doc) doc <- gsub("can't", "can not", doc) doc <- gsub("n't", " not", doc) doc <- gsub("'ll", " will" , doc) doc <- gsub("'re", " are", doc) doc <- gsub("'ve", " have", doc) doc <- gsub("'m", " am" , doc) doc <- gsub("'d", " would", doc) doc <- gsub("'s","",doc) return(doc) } prince$lyrics<-sapply (prince$lyrics,fix.contractions) 5、删除一些特殊字符 removeSpecialChars<-function(x)gsub("[^a-zA-Z0-9]"," ",x

    97320发布于 2020-03-03
  • 来自专栏蓝天

    awk用法小结

    13、awk 'gsub(/\$/,"");gsub(/,/,""); cost+=$4;          END {print "The total is $" cost>"filename"}'     file gsub函数用空串替换$和,再将结果输出到filename中。     1 2 3 $1,200.00     1 2 3 $2,300.00     1 2 3 $4,000.00     awk '{gsub(/\$/,"");gsub(/,/,"");     (/\$/,"");gsub(/,/,"");     if ($4>3000&&$4<4000) exit;     else c4+=$4; }     END {printf  "c1=[% awk '{gsub(/\$/,"");gsub(/,/,"");     if ($4>3000) next;     else c4+=$4; }     END {printf  "c4=[

    1.5K30发布于 2019-03-14
  • 来自专栏数据科学(冷冻工厂)

    ATAC-seq分析:数据处理(5)

    nucFreeRegionBam <- gsub("\\.bam", "_nucFreeRegions\\.bam", sortedBAM) monoNucBam <- gsub("\\.bam", " _monoNuc\\.bam", sortedBAM) diNucBam <- gsub("\\.bam", "_diNuc\\.bam", sortedBAM) library(rtracklayer openRegionRPMBigWig <- gsub("\\.bam", "_openRegionRPM\\.bw", sortedBAM) myCoverage <- coverage(atacFragments

    47920编辑于 2023-02-27
  • 使用awk命令5秒替换700M文件内容

    命令如下:awk -i inplace '{gsub("<table_name>", "u_user")} 1' 无标题2.sql我这个sql文件大小为700M,替换也只要5秒左右 gsub函数参数:第一个为要查找的字符串 ,第二个为要替换的字符串,如将1替换为2,则gsub参数为:gsub("1", "2")。 

    33500编辑于 2025-02-20
  • 来自专栏单细胞天地

    胃癌单细胞数据集GSE163558复现(一):数据下载、整理与读取

    因此我们可以利用文本处理函数”str_split“、”gsub“对患者编号进行处理,并添加以上信息到meta.data。 ("GSM\\d+_PT\\d+", "GC", phe$sample) phe$sample = gsub("GSM\\d+_LN\\d+", "GC_lymph_metastasis", phe$ sample) phe$sample = gsub("GSM\\d+_O1", "GC_ovary_metastasis", phe$sample) phe$sample = gsub("GSM\\ _Li1", "Patient1", phe$patient) phe$patient = gsub("GSM5004181_PT2|GSM5004183_NT1", "Patient2", phe$ patient) phe$patient = gsub("GSM5004186_O1", "Patient3", phe$patient) phe$patient = gsub("GSM5004185

    4.5K15编辑于 2024-06-13
  • 来自专栏程序员奇点

    logstash.filter.kv Exception while parsing kv 解决办法

    在 custmsg 中去掉 "\n" 试试 mutate { gsub => [ "custmsg","\n", "" , } 下面介绍 logstash mutate 插件 mutate插件可以对事件中的数据进行修改,包括rename、update、replace、convert、split、gsub filter { mutate { convert => ["request_time", "float"] } } 5、gsub gsub 提供了通过正则表达式实现文本替换的功能 filter { mutate { gsub => [ # replace all forward slashes with underscore

    1.1K10发布于 2020-02-17
  • 来自专栏生信菜鸟团

    Nature文章复现|早期肺鳞状癌发生过程中关于肿瘤侵袭前免疫逃逸机制的表达量芯片研究

    ("normal normofluorescent",1,stage) stage<-gsub("normal hypofluorescent",2,stage) stage<-gsub("hyperplasia ",3,stage) stage<-gsub("metaplasia",4,stage) stage<-gsub("mild dysplasia",5,stage) stage<-gsub("moderate dysplasia",6,stage) stage<-gsub("severe dysplasia",7,stage) stage<-gsub("carcinoma in situ",8,stage) =""]->m factor(group_list)->stage stage<-gsub("normal normofluorescent",1,stage) stage<-gsub("normal <-gsub("mild dysplasia",5,stage) stage<-gsub("moderate dysplasia",6,stage) stage<-gsub("severe dysplasia

    51510编辑于 2024-01-04
领券