i'm new to R and stuck with the following data. Either i searched with the wrong terms or this question has not been risen (maybe due to simplicity?).
i have a data frame containing factors and numerical columns:
> head(PAMdata1)
salt cultivar Ratiod13 StdErr
1 50 1 1.0760163 0.02915785
2 100 1 0.9814083 0.04914316
3 50 2 0.9617199 0.06571578
4 100 2 0.7878740 0.10270647
5 50 4 0.9551830 0.04134652
6 100 4 0.8429793 0.10993336
> str(PAMdata1)
'data.frame': 36 obs. of 4 variables:
$ salt : Factor w/ 2 levels "50","100": 1 2 1 2 1 2 1 2 1 2 ...
$ cultivar: Factor w/ 18 levels "27","26","21",..: 7 7 15 15 13 13 11 11 9 9 ...
$ Ratiod13: num 1.076 0.981 0.962 0.788 0.955 ...
$ StdErr : num 0.0292 0.0491 0.0657 0.1027 0.0413 ...
The column 'cultivar' contains factors, whose levels are ordered using another data frame:
PAMdata1$cultivar <- factor(PAMdata1$cultivar, levels = unique(as.character(my_other_df$cultivar)))
levels(PAMdata1$cultivar)
[1] "27" "26" "21" "52" "14" "25" "1" "23" "7" "8" "5" "28" "4" "22" "2"
[16] "53" "51" "50"
What i would like to have is PAMdata1$Ratiod13 ordered by the levels of cultivars. How do i transform the vector of levels into a vector of line numbers each level is located in?
I would appreciate any help on this.
Thanks a lot