Hi everyone,
I am new at R programing, and I am struggling with something quite simple I assume. The idea here is to rename strings in my dataframe and then merge 2 data frames
the merging seems to work fine but the rename is causing problems
Could someone help me with that ?
thanks
setwd("~/Get consolidated file")
load xlsx library
library("xlsx")
library(stringr)
read xlsx files
read_data2 <- read.xlsx("shiny.xlsx",1, check.names = FALSE)
read_data <- read.xlsx("Tracking.xlsx",1, check.names = FALSE)
#Change and rename headers
colnames(read_data) <- gsub('StimulusConcentration', "TreatmentGroupName", colnames(read_data))
colnames(read_data2) <- gsub('StimulusConcentration', "TreatmentGroupName", colnames(read_data2))
#change all occurences from the dataframe
str_replace_all(read_data, c("TRO_0uM" = "TRO_0.03uM", "TRIN-5_0uM" = "TRIN-5_0.03uM"))
#here results are displayed with [1] "c("
and when I run read_data another dataframe without the replacements is displayed
I just need to export my dataframe with the modifications but I cannot
#Merge the 2 xlsx based on ChildSampleID
x <- merge(read_data2, read_data, by = "SampleID", all.x = TRUE, all.y = TRUE)
write.table(read_data, file = "toto.txt", quote = FALSE, sep = "\t", col.names = TRUE,
row.names = FALSE)