0

I wrote:

library(dplyr)

mutate(cell_line = gsub("cell_line: ", "" , cell_line)) %>%
  mutate(genotype_or_treatment = gsub("treatment:  ", "_" , genotype_or_treatment)) %>%
  head()

enter image description here

I was expecting the line "cell_line: " to be replaced with a space/"" in the table, but alas nothing changed. Same with "treatment: ".

benson23
  • 16,369
  • 9
  • 19
  • 38
meeks
  • 1
  • 1
  • 1
    Hi meeks! Welcome to StackOverflow. Please provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Mark Jun 30 '23 at 06:35
  • 1
    It looks like you're trying to substitute "cell_line" but the actual text in your column is "cell line". But without a reproducible example its hard to tell what is actually going on. – Godrim Jun 30 '23 at 07:28

1 Answers1

0

Your example is not a minimally reproducible one, it is hard to actually test the code I am about to propose, but it is worth a try.

library(tidyverse)

metadata_corrected <- metadata %>%
  mutate(cell_line = str_replace_all(cell_line, "cell_line: ", ""),
         genotype_or_treatment = str_replace_all(genotype_or_treatment, "treatment: ", ""))

metadata_corrected

Hope this works for you!

ATpoint
  • 603
  • 5
  • 17
U Bhalraam
  • 96
  • 7