Comparing two vectors and arrange one elements of vector with respect other vector if not in same order

r
data_mining

#1

i have vector like this
new_vect
[1] “b” “d” “c” “e” “h” “f” “g”

and i have data frame like
b d
b c f g h
b c d e f h
c e g h
d
b
d e

now i want to compare each row of dataframe with new_vect, and arrange the elements of row in dataframe as like in new_vect

for ex
in 2nd row of dataframe i have " b c f g h" these should arrange like “b c h f g”


#2

Hi @revathi

This is doable using the for loops in R. You’ll need to manually write the code to sort dataframe rows in order of the vector that you have.

If you find it difficult. I am willing to assist you with code if you can provide me with the sample data in csv format.

Best,
Saurav.


#3

yeah i tried with for loops but i am not getting proper output, i am attaching toy dataset plz assist me with code…thanking You :slight_smile: