My question is if I have the next data frame in R.
a<-data.frame(col1=c("a","a","a","d","a"),
col2=c("b","b","c","e","e"),
col3=c("c","d","e",NA,NA),
col4=c("d","e",NA,NA,NA),
col5=c("e",NA,NA,NA,NA))
print(a)
col1| col2| col3| col4| col5|
a b c d e
a b d e NA
a c e NA NA
d e NA NA NA
a e NA NA NA
I need other data frame like this:
b<-data.frame(col1=c("a","a","a",NA,"a"),
col2=c("b","b",NA,NA,NA),
col3=c("c",NA,"c",NA,NA),
col4=c("d","d",NA,"d",NA),
col5=c("e","e","e","e","e"))
print(b)
col1| col2| col3| col4| col5|
a b c d e
a b NA d e
a NA c NA e
NA NA NA d e
a NA NA NA e
Sorry, I don't have the concepts to explain my problem, is for this reason that I question ask, but I guess that, I want first: separate by columns rows that be distinct to rest of group in a new column, and second, to get the rows that have the same values in a same column.
I think that my problem is similar to this: Split unique values into separate columns for multiple columns
If someone can help me I will be very thankful.
dputof the input example - akrunt(apply(df1, 1, function(x) {v1 <- character(length(x)); v1[match(x, letters, nomatch = 0)] <- x; v1}))- akrun