Replace entire expression that contains a specific string

后端 未结 2 1106
花落未央
花落未央 2021-01-03 13:06

I have data frame that has a column with large number of file names like:

d <- c(\"harry11_scott80_norm.avi\",\"harry11_norm.avi\",\"harry11_scott80_lpf.         


        
2条回答
  •  情歌与酒
    2021-01-03 13:13

    If your filenames are all of the same format, that is those with two names i.e harry11_scott80_norm.avi always have two underscores, and those with one name i.e. harry11_norm.avi always have one underscore, you can quickly use something like this to rename your files:

    d = gsub(".*_.*_.*", "incongruent", d)
    > d
    [1] "incongruent"      "harry11_norm.avi" "incongruent"      "joel51_lpf.avi"  
    [5] "incongruent"
    
    d =gsub(".*_.*","congruent",d)
    > d
    [1] "incongruent" "congruent"   "incongruent" "congruent"   "incongruent"
    

提交回复
热议问题