Below are the solutions to these exercises on sorting and ordering.

############### # # # Exercise 1 # # # ############### library(RDSTK) ############### # # # Exercise 2 # # # ############### s1="statistics" s3="value" stringer= function(s2){ s1="statistics" s3="value" s2=as.character(s2) return(paste(s1,s2,s3, sep = ".")) } ############### # # # Exercise 3 # # # ############### stringer("hello")

## [1] "statistics.hello.value"

############### # # # Exercise 4 # # # ############### for (i in 1:nrow(df)) { df$pop[i]=coordinates2statistics(df[i,4],df[i,7],"population_density")["statistics.population_density.value"] } df

## X ip.address dma_code latitude country_code3 area_code longitude ## 1 1 165.124.145.197 602 42.0586 USA 847 -87.6845 ## 2 2 31.24.74.155 0 57.1000 SWE 0 12.2500 ## 3 3 79.129.19.173 0 39.7378 GRC 0 22.2892 ## country_name postal_code region locality country_code pop pop2 ## 1 United States 60208 IL Evanston US 3040 3040 ## 2 Sweden NA 06 Varberg SE 60 60 ## 3 Greece NA 21 Tírnavos GR 33 33

############### # # # Exercise 5 # # # ############### stat_maker=function(s2){ s1="statistics" s3="value" s2=as.character(s2) for (i in 1:nrow(df)) { df$pop2[i]=coordinates2statistics(df[i,4],df[i,7],s2)[paste(s1,s2,s3, sep = ".")] } return(df)} ############### # # # Exercise 6 # # # ############### stat_maker("population_density")

############### # # # Exercise 7 # # # ############### stat_maker=function(s2){ s1="statistics" s3="value" s2=as.character(s2) for (i in 1:nrow(df)) { df$pop2[i] <<-coordinates2statistics(df[i,4],df[i,7],s2)[paste(s1,s2,s3, sep = ".")] } } stat_maker("population_density") ############### # # # Exercise 8 # # # ############### assign("test",50) test

## [1] 50

############### # # # Exercise 9 # # # ############### stat_maker=function(s2){ s1="statistics" s3="value" s2=as.character(s2) for (i in 1:nrow(df)) { df$pop2[i] <<-coordinates2statistics(df[i,4],df[i,7],s2)[paste(s1,s2,s3, sep = ".")] assign("test2",50) } } stat_maker("population_density") test2

## Error in eval(expr, envir, enclos): object 'test2' not found

############### # # # Exercise 10 # # # ############### stat_maker=function(s2){ s1="statistics" s3="value" s2=as.character(s2) for (i in 1:nrow(df)) { df$pop2[i] <<-coordinates2statistics(df[i,4],df[i,7],s2)[paste(s1,s2,s3, sep = ".")] assign("test2",50,envir = .GlobalEnv) } } stat_maker("population_density") test2

## [1] 50

## Leave a Reply