0

I have two dataframes:

df1<-matrix(data = 1:10,
nrow = 5,
ncol = 5)
colnames(df1)=c("a","b","c","d","e")

df2=c("a","c","e")

I want to create a new table using the values from the first data frame but including only the columns whose name is present in the second data frame.

1 Answers1

1

Try adding below to your code

df3 <- data.frame(df1[,df2]) 
leonhnoel
  • 28
  • 5