i have dataframe looks this.
abdominal pain chest pain flu-like liver damage nausea numbness swelling avandaia 1 0 0 1 1 1 1 warfrin 0 1 1 0 1 1 1 flu-like 0 0 0 0 0 0 0 liver damage 0 0 0 0 0 0 0 nausea 0 0 0 0 0 0 0 numbness 0 0 0 0 0 0 0 swelling 0 0 0 0 0 0 0
i want edgelist looks this:
abdominal pain | avandaia chest pain | warfrin flu-like | warfrin liver damage | avandaia nausea | avanadia nausea | warfrin .... ....
i've used r's igraph package before get.edgelist adjacency matrix, believe in case rownames , column names must match. how can dataframe there different row , column names?
thanks!
some solutions without using igraph
df <- read.csv(text="drug,abdominal pain,chest pain,flu-like,liver damage,nausea,numbness,swelling avandaia,1,0,0,1,1,1,1 warfrin,0,1,1,0,1,1,1 flu-like,0,0,0,0,0,0,0 liver damage,0,0,0,0,0,0,0 nausea,0,0,0,0,0,0,0 numbness,0,0,0,0,0,0,0 swelling,0,0,0,0,0,0,0 ", check.names=false) library(tidyr) gather_(df, "symptom", "count", setdiff(names(df),"drug")) %>% filter(count > 0) library(data.table) setdt(df) melt.data.table(df, measure.vars=setdiff(names(df),"drug"))[value>0]
Comments
Post a Comment