R combining a df with a factor

I am pretty new to R and am trying to combine a df with a factor.

My df is a dataframe of 300 by 2, and the factor is created from sampling the 300 rows and assigning them to 1,2,3. I would like to know how to combine my factor to the df. Basically, I want the factor variable shown as a column of my df.

I tried merge(db, factor) but it did not work. I also tried to turn the factor variable into a df, but still couldn't get it to work.

Read more here: https://stackoverflow.com/questions/64938968/r-combining-a-df-with-a-factor

Content Attribution

This content was originally published by TianShu Fan at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: