Pls how can i rename each columns after str_split()
operations in data frames
Here i created example data set
library(stringr)
#create data frame
samples <- paste0("sample", 1:5)
tags <- paste("tag", LETTERS[1:5],sep="_")
df1 <- data.frame(sample_plus_tag = paste(samples, tags, sep="_"))
#split sample columns
df1 <- df1 %>% mutate(sample=str_split_fixed(string=sample_plus_tag, pattern="_", n=2))
dim(df1)
names(df1) <- c("sample_plus_tag","sample","tags")
but i get the error. however i was thinking number of columns should be 3
[1] 5 2
Error in names(df1) <- c("sample_plus_tag", "sample", "tags") :
'names' attribute [3] must be the same length as the vector [2]