I have a lot of variables and the column numbers will change and I'm trying to subset by different columns for some of my plots. I need to keep all of my data together but need a way to globally identify columns. After I get the suffixes pasted to the variable names, I plan to use grepl to grab all of the columns that I need for plots.
The following code gives me the "_Z" for all of the columns. How would I do it with just indicator2 and indicator5? Again, I can't use column numbers. I'm going to have to use the many (~100) column names to rename them.
df_1 <- data.frame(
categorical = c("A","B","C","A","B","A","C","C","C","A","A","C","C","C","A","C","A","B","A","C"),
indicator1 = c(1,0,1,0,1,0,0,0,0,0,0,0,0,1,1,0,1,0,0,1),
indicator2 = c(1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0),
indicator3 = c(1,0,1,0,1,0,1,0,1,0,0,1,1,0,1,0,1,0,1,0),
indicator4 = c(0,1,0,0,1,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0),
indicator5 = c(0,0,1,1,1,0,1,0,1,0,1,1,1,1,1,0,0,0,0,0),
continuous1 = c(2.3,3.4,6.6,5.5,6,7,11,12.3,13,5,2.4,3.6,6.3,5.2,5,6.6,11.3,12,14,5),
gender = c("M","M","F","F","F","F","F","F","M","U","U","F","M","M","F","F","F","U","M","F"))
print(df_1)
#summary(df_1)
temp <- names(df_1)
put a "_Z" at end
names <- paste0(temp, "_Z")
names(df_1) <- names
df_1