moroccostats has a structure
> str(moroccostats) 'data.frame': 91 obs. of 38 variables: $ year : Factor w/ 91 levels "1960","1961",..: 1 2 3 4 5 6 7 8 9 10 ... $ periodframe : Factor w/ 4 levels "0","Phase 1 (1965 to 1985)",..: 1 1 1 1 1 2 2 2 2 2 ... $ pop_t : num 11635 11897 12177 12473 12785 ... $ pop_ur : num 3395 3547 3703 3862 4026 ... ...
When you swim to get the year moroccostats.f , you will get
> str(moroccostats.f) 'data.frame': 3367 obs. of 3 variables: $ year : Factor w/ 91 levels "1960","1961",..: 1 2 3 4 5 6 7 8 9 10 ... $ variable: Factor w/ 37 levels "periodframe",..: 1 1 1 1 1 1 1 1 1 1 ... $ value : chr "0" "0" "0" "0" ...
Note that value is a symbol because periodframe was a factor. I assume that the periodframe changed from a number to a character (bit of phase 1 (1965-1985)).
Since you only draw the columns pop_t and pop_ur and pop_ru , pull them out before melting
morstats.pop <- melt(moroccostats[c("year","pop_t","pop_ur","pop_ru")], id="year")
then you donโt need to worry about enforcing other types of fees for inappropriate columns.
source share