Q:

Keep quotes when creating data frame in R

I have a data frame df containing many columns. From these, I extract two (col1 and col2) and use df2 = data.frame(df$col1, df$col2) for this.
It works: a new dataframe made of those two columns is created. But df$col1 was made of strings as:
"test1"
"test2"

df2$col1 is made instead of values (not sure how to call them) as:
test1
test2

Intersection between these df$col1 and df2$col1 yields zero. How do I keep the column as a string in the new data frame?
I tried adding stringsAsFactors = FALSE but nothing changed.

A:

'df' is your data frame and you do not want to change the original data type. i.e., you should retain your string data type. 
So basically you should subset those columns from the original data frame instead of creating a new data frame using 'data.frame'.
> df2<-df[,c("col1","col2")]

You can check the data type of each column in data frame by
> str(df2)

