Entering edit mode
3.0 years ago
maria2019
▴
250
I have a dataframe with many cols. Some of the cols have vectors in them. What I want to do, is for everything in the df, if the elements of the vectors are identical, to change the vector to one element but if there is at least one difference, to keep it.
an example of my dataframe:
this is the output that I want
Basically,
> if length(unique(each_vector))==1-> do nothing , otherwise, only choose the first element of the vector.
I would be thankful if someone could help
I guess first, how did you end up in this situation? Second, are the data frame elements lists, or are they filled with strings like
"c(1, 2, 3)"
?No, they are not filled with strings. exactly same as the photo that I have posted.
it is the out put of the following code:
Can you add your data to the post with
dput(df)
?