Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listing all the diferent strings from a dataframe in R

i'm still a newbie with R and I can't figure this out. I have a dataframe that looks like this:

Age         State     Diagnosis
 12         Texas   Lung Cancer
 67    California  Colon Cancer
 45       Wyoming   Lung Cancer
 36      New Mex.      Leukemia
 58       Arizona  Colon Cancer
 35      Colorado      Leukemia

I need a program that somehow prints or adds into another dataframe all the different strings that are located in each column. So I can Know all the "types". For example, in the case of the column "diagnosis", the program should create a dataframe with only "Lung cancer, colon cancer and leukemia" since there are only those 3 types, even though they are repeated.

like image 461
MHernandez22 Avatar asked Mar 02 '23 13:03

MHernandez22


1 Answers

You can use unique.

Assuming you have a dataframe data with all the information, you can use the function unique() to list all the occurences, removing repetitions:

types <- unique(data$diagnosis)
like image 69
Louis Avatar answered Mar 05 '23 08:03

Louis