У меня есть данные со многими столбцами, которые я хочу преобразовать в объект igraph. Некоторые значения существуют в нескольких столбцах, поэтому я хочу добавить имя столбца, чтобы идентифицировать эти значения. Ниже приведен воспроизводимый пример.
# sample of original data
head(as.data.frame(Titanic))
# sample of the data after the col name has been appended to the value of the column
data.frame(Class = c("Class_1st","Class_2nd","Class_3rd","Class_Crew","Class_1st","Class_2nd"),
Sex = c("Sex_Male","Sex_Male","Sex_Male","Sex_Male","Sex_Female","Sex_Female"),
Age = c("Age_Child","Age_Child","Age_Child","Age_Child","Age_Child","Age_Child"),
Survived = c("Survived_No","Survived_No","Survived_No","Survived_No","Survived_No","Survived_No"),
Freq = c(0,0,35,0,0,0), stringsAsFactors = FALSE)