问题 This question already has answers here : Reshaping data.frame from wide to long format (9 answers) Counting unique / distinct values by group in a data frame (10 answers) Closed 3 days ago . I have a dataset with 4 columns containing names, where the number of names and the order of names differ between columns. Some columns can also contain the same name twice or more. It looks like follows: df<- data.frame(x1=c("Ben","Alex","Tim", "Lisa", "MJ","NA", "NA","NA","NA"), x2=c("Ben","Paul","Tim",