[R] cut variable within a loop
Janka Vanschoenwinkel
janka.vanschoenwinkel at uhasselt.be
Fri Aug 14 15:40:59 CEST 2015
Hi Petr,
Here the code below:
load("data.Rda") # or see data at the bottom of this email
##########################################################################################
####### Question cut2 intervals #######
# I have the variable irrigation which has a range from 0% to 100%.
# I now want to calculate the code below for different thresholds of irrigation.
# So for instance: starting from 10%, a farmer is defined as "irrigated farm".
# Then we would have 0-10 = Rainfed, 10-100 is Irrigated.
# In the code below I run a short code for only 50 observations and
# only for the interval 0-1,1-100 and 0-2, 2-100. If that works, it should also
# work for 1-99.
# As indicated, it goes wrong when I want to cut based on the "i"
specified at the start of the loop.
# Thanks a lot for your help!
# Janka
d= data.frame(MEt_Rainfed=rep(1,2),MEp_Rainfed=rep(1,2),MEt_Irrigation=rep(1,2),MEp_Irrigation=rep(1,2))
library(Hmisc)
o<-lapply(1:2, function(i){
#cut sample in rainfed versus irrigation
Alldata$irri=cut2(Alldata$irrigation,i)
levels(Alldata$irri)<-c("0","1")
Alldata_Rainfed<-subset(Alldata, irri == 0)
Alldata_Irrigation<-subset(Alldata, irri == 1)
Alldata_Rainfed$w<-Alldata_Rainfed$b48+Alldata_Rainfed$b50
Alldata_Irrigation$w<-Alldata_Irrigation$b48+Alldata_Irrigation$b50
OLS_Rainfed <- lm(LnALVperHA~ps1+ps2+ps3+ps4+ts1+ts2+ts3+ts4+
ps1sq+ps2sq+ps3sq+ps4sq+ts1sq+ts2sq+ts3sq+ts4sq+
pdnsty+portsML+cities500k+rentedland+subsidies1+
elevmean+elevrange+
t_gravel+t_gravel+t_ph_h2o+t_silt+t_sand+
AT+BE+DK+ES+FI+FR+GR+IE+IT+LU+NL+PT+SE+WDE+EDE+UK,
weights=w,Alldata_Rainfed)
attach(Alldata_Rainfed)
CoefRainfed_ps1 <- OLS_Rainfed$coeff[2]
CoefRainfed_ps2 <- OLS_Rainfed$coeff[3]
CoefRainfed_ps3 <- OLS_Rainfed$coeff[4]
CoefRainfed_ps4 <- OLS_Rainfed$coeff[5]
CoefRainfed_ts1 <- OLS_Rainfed$coeff[6]
CoefRainfed_ts2 <- OLS_Rainfed$coeff[7]
CoefRainfed_ts3 <- OLS_Rainfed$coeff[8]
CoefRainfed_ts4 <- OLS_Rainfed$coeff[9]
CoefRainfed_ps1sq <- OLS_Rainfed$coeff[10]
CoefRainfed_ps2sq <- OLS_Rainfed$coeff[11]
CoefRainfed_ps3sq <- OLS_Rainfed$coeff[12]
CoefRainfed_ps4sq <- OLS_Rainfed$coeff[13]
CoefRainfed_ts1sq <- OLS_Rainfed$coeff[14]
CoefRainfed_ts2sq <- OLS_Rainfed$coeff[15]
CoefRainfed_ts3sq <- OLS_Rainfed$coeff[16]
CoefRainfed_ts4sq <- OLS_Rainfed$coeff[17]
attach(Alldata_Rainfed)
###### MARGINAL EFFECTS SEASONAL and YEARLY and REGIONAL (EU or COUNTRY level)
# Maar dit is dus de marginale impact per LnALVperHA?
Alldata_Rainfed$MEts1 =
CoefRainfed_ts1+2*CoefRainfed_ts1sq*Alldata_Rainfed$ts1
Alldata_Rainfed$MEts2 =
CoefRainfed_ts2+2*CoefRainfed_ts2sq*Alldata_Rainfed$ts2
Alldata_Rainfed$MEts3 =
CoefRainfed_ts3+2*CoefRainfed_ts3sq*Alldata_Rainfed$ts3
Alldata_Rainfed$MEts4 =
CoefRainfed_ts4+2*CoefRainfed_ts4sq*Alldata_Rainfed$ts4
Alldata_Rainfed$MEt = Alldata_Rainfed$MEts1 +
Alldata_Rainfed$MEts2 + Alldata_Rainfed$MEts3 + Alldata_Rainfed$MEts4
Alldata_Rainfed$MEps1 =
CoefRainfed_ps1+2*CoefRainfed_ps1sq*Alldata_Rainfed$ps1
Alldata_Rainfed$MEps2 =
CoefRainfed_ps2+2*CoefRainfed_ps2sq*Alldata_Rainfed$ps2
Alldata_Rainfed$MEps3 =
CoefRainfed_ps3+2*CoefRainfed_ps3sq*Alldata_Rainfed$ps3
Alldata_Rainfed$MEps4 =
CoefRainfed_ps4+2*CoefRainfed_ps4sq*Alldata_Rainfed$ps4
Alldata_Rainfed$MEp = Alldata_Rainfed$MEps1 +
Alldata_Rainfed$MEps2 + Alldata_Rainfed$MEps3 + Alldata_Rainfed$MEps4
Alldata_Rainfed$weight2<-Alldata_Rainfed$b48+Alldata_Rainfed$b50
attach(Alldata_Rainfed)
library(stats)
MEt_Rainfed<-weighted.mean(MEt,weight2)
MEp_Rainfed<-weighted.mean(MEp,weight2)
attach(Alldata_Irrigation)
OLS_Irrigation <- lm(LnALVperHA~ps1+ps2+ps3+ps4+ts1+ts2+ts3+ts4+
ps1sq+ps2sq+ps3sq+ps4sq+ts1sq+ts2sq+ts3sq+ts4sq+
pdnsty+portsML+cities500k+rentedland+subsidies1+
elevmean+elevrange+
t_gravel+t_gravel+t_ph_h2o+t_silt+t_sand+
AT+BE+DK+ES+FI+FR+GR+IE+IT+LU+NL+PT+SE+WDE+EDE+UK,
weights=w,Alldata_Irrigation)
CoefIrrigation_ps1 <- OLS_Irrigation$coeff[2]
CoefIrrigation_ps2 <- OLS_Irrigation$coeff[3]
CoefIrrigation_ps3 <- OLS_Irrigation$coeff[4]
CoefIrrigation_ps4 <- OLS_Irrigation$coeff[5]
CoefIrrigation_ts1 <- OLS_Irrigation$coeff[6]
CoefIrrigation_ts2 <- OLS_Irrigation$coeff[7]
CoefIrrigation_ts3 <- OLS_Irrigation$coeff[8]
CoefIrrigation_ts4 <- OLS_Irrigation$coeff[9]
CoefIrrigation_ps1sq <- OLS_Irrigation$coeff[10]
CoefIrrigation_ps2sq <- OLS_Irrigation$coeff[11]
CoefIrrigation_ps3sq <- OLS_Irrigation$coeff[12]
CoefIrrigation_ps4sq <- OLS_Irrigation$coeff[13]
CoefIrrigation_ts1sq <- OLS_Irrigation$coeff[14]
CoefIrrigation_ts2sq <- OLS_Irrigation$coeff[15]
CoefIrrigation_ts3sq <- OLS_Irrigation$coeff[16]
CoefIrrigation_ts4sq <- OLS_Irrigation$coeff[17]
attach(Alldata_Irrigation)
# gives the residual errors in Y
Alldata_Irrigation$residuals <-resid(OLS_Irrigation)
# gives the predicted values for Ln_Y
Alldata_Irrigation$Ln_y_hat <-fitted(OLS_Irrigation)
# Zelf functie rmse maken
rmse <- function(error)
{
sqrt(mean(error^2))
}
Alldata_Irrigation$y_hat <-
exp(Alldata_Irrigation$Ln_y_hat)*exp(0.5*(rmse(OLS_Irrigation$residuals))^2)
# absolute impact (landwaarde current)
Alldata_Irrigation$absolute.current<-Alldata_Irrigation$y_hat*Alldata_Irrigation$se025*Alldata_Irrigation$sys02
###### MARGINAL EFFECTS SEASONAL and YEARLY and REGIONAL (EU or COUNTRY level)
# Maar dit is dus de marginale impact per LnALVperHA?
Alldata_Irrigation$MEts1 =
CoefIrrigation_ts1+2*CoefIrrigation_ts1sq*Alldata_Irrigation$ts1
Alldata_Irrigation$MEts2 =
CoefIrrigation_ts2+2*CoefIrrigation_ts2sq*Alldata_Irrigation$ts2
Alldata_Irrigation$MEts3 =
CoefIrrigation_ts3+2*CoefIrrigation_ts3sq*Alldata_Irrigation$ts3
Alldata_Irrigation$MEts4 =
CoefIrrigation_ts4+2*CoefIrrigation_ts4sq*Alldata_Irrigation$ts4
Alldata_Irrigation$MEt = Alldata_Irrigation$MEts1 +
Alldata_Irrigation$MEts2 + Alldata_Irrigation$MEts3 +
Alldata_Irrigation$MEts4
Alldata_Irrigation$MEps1 =
CoefIrrigation_ps1+2*CoefIrrigation_ps1sq*Alldata_Irrigation$ps1
Alldata_Irrigation$MEps2 =
CoefIrrigation_ps2+2*CoefIrrigation_ps2sq*Alldata_Irrigation$ps2
Alldata_Irrigation$MEps3 =
CoefIrrigation_ps3+2*CoefIrrigation_ps3sq*Alldata_Irrigation$ps3
Alldata_Irrigation$MEps4 =
CoefIrrigation_ps4+2*CoefIrrigation_ps4sq*Alldata_Irrigation$ps4
Alldata_Irrigation$MEp = Alldata_Irrigation$MEps1 +
Alldata_Irrigation$MEps2 + Alldata_Irrigation$MEps3 +
Alldata_Irrigation$MEps4
Alldata_Irrigation$weight2<-Alldata_Irrigation$sys02*Alldata_Irrigation$se025
Alldata_Irrigation$weight2<-Alldata_Irrigation$b48+Alldata_Irrigation$b50
attach(Alldata_Irrigation)
library(stats)
MEt_Irrigation<-weighted.mean(MEt,weight2)
MEp_Irrigation<-weighted.mean(MEp,weight2)
c(MEt_Rainfed,MEp_Rainfed,MEt_Irrigation,MEp_Irrigation)
attach(Alldata)
# And in the loop (index i):
d[i, ] = c(MEt_Rainfed,MEp_Rainfed,MEt_Irrigation,MEp_Irrigation)
})
out<-as.data.frame(do.call(rbind, o))
And the data are:
structure(list(LnALVperHA = c(8.09964942932129, 9.53274631500244,
7.42697763442993, 8.25370121002197, 8.42619132995605, 8.0093936920166,
8.09785747528076, 8.49044704437256, 9.08215141296387, 8.38935947418213,
8.67814350128174, 8.38935947418213, 10.4056901931763, 8.48210144042969,
8.30281829833984, 8.92265796661377, 8.33178997039795, 4.54404163360596,
10.662184715271, 9.62167072296143, 7.98790407180786, 7.58244323730469,
7.23262739181519, 9.47037124633789, 8.93403625488281, 7.54256629943848,
9.40302467346191, 10.6290521621704, 8.59830188751221, 8.59585666656494,
9.10000514984131, 9.99381542205811, 9.54681301116943, 9.53055191040039,
8.67971229553223, 7.19780731201172, 8.90067958831787, 6.0509786605835,
6.55788946151733, 8.22567272186279, 9.05618953704834, 6.81858921051025,
8.46410751342773, 7.81292057037354, 8.38989448547363, 10.4709157943726,
8.06132888793945, 8.43629264831543, 10.3087100982666, 10.3218297958374
), ps1 = c(5.14855766296387, 4.71904611587524, 7.9462103843689,
10.6017990112305, 11.233078956604, 9.12952136993408, 12.6536712646484,
11.233078956604, 11.233078956604, 11.233078956604, 11.233078956604,
11.233078956604, 5.93759632110596, 10.6017990112305, 11.233078956604,
10.6017990112305, 7.95780467987061, 9.07744884490967, 4.29865598678589,
8.27481746673584, 3.25137901306152, 4.51061344146729, 6.34518480300903,
6.66202449798584, 6.66202449798584, 4.75249433517456, 6.28858852386475,
6.33270215988159, 10.3600759506226, 10.3600759506226, 18.7164611816406,
5.73318386077881, 7.92949104309082, 9.09823608398438, 11.233078956604,
10.4455404281616, 11.233078956604, 10.4455404281616, 10.4455404281616,
10.6017990112305, 9.19112777709961, 10.4455404281616, 11.233078956604,
11.064302444458, 11.233078956604, 5.93759632110596, 11.233078956604,
10.6017990112305, 6.05948448181152, 9.5645227432251), ps2 = c(5.23111915588379,
4.86784505844116, 7.7175760269165, 4.34898376464844, 4.48626232147217,
9.57159423828125, 8.38174915313721, 4.48626232147217, 4.48626232147217,
4.48626232147217, 4.48626232147217, 4.48626232147217, 6.87198734283447,
4.34898376464844, 4.48626232147217, 4.34898376464844, 6.2098217010498,
7.5497522354126, 5.62545442581177, 5.57168531417847, 3.08954334259033,
6.6683931350708, 4.41767883300781, 6.11901044845581, 6.11901044845581,
4.06884765625, 6.35917854309082, 5.7121729850769, 8.55229663848877,
8.55229663848877, 11.8981914520264, 5.49351119995117, 5.34777498245239,
6.12420177459717, 4.48626232147217, 5.2967677116394, 4.48626232147217,
5.2967677116394, 5.2967677116394, 4.34898376464844, 4.51386308670044,
5.2967677116394, 4.48626232147217, 5.98725175857544, 4.48626232147217,
6.87198734283447, 4.48626232147217, 4.34898376464844, 5.58411026000977,
4.42436075210571), ps3 = c(4.95634937286377, 3.50353670120239,
6.01129817962646, 0.851324141025543, 0.816295921802521, 8.03804397583008,
5.56230783462524, 0.816295921802521, 0.816295921802521, 0.816295921802521,
0.816295921802521, 0.816295921802521, 6.01666784286499, 0.851324141025543,
0.816295921802521, 0.851324141025543, 3.45424580574036, 5.31899690628052,
7.45753812789917, 3.34133338928223, 6.61472988128662, 11.244439125061,
2.19617891311646, 5.29748106002808, 5.29748106002808, 1.63307499885559,
5.51272773742676, 6.78562116622925, 4.5334997177124, 4.5334997177124,
4.31791353225708, 7.10963106155396, 2.32198905944824, 2.74845194816589,
0.816295921802521, 1.47570741176605, 0.816295921802521, 1.47570741176605,
1.47570741176605, 0.851324141025543, 1.39068424701691, 1.47570741176605,
0.816295921802521, 1.85064959526062, 0.816295921802521, 6.01666784286499,
0.816295921802521, 0.851324141025543, 6.78009986877441, 1.21070051193237
), ps4 = c(5.66667366027832, 4.82342433929443, 7.40090322494507,
6.59299898147583, 7.33758926391602, 9.98004341125488, 10.3958940505981,
7.33758926391602, 7.33758926391602, 7.33758926391602, 7.33758926391602,
7.33758926391602, 8.31999015808105, 6.59299898147583, 7.33758926391602,
6.59299898147583, 7.05771064758301, 8.38344383239746, 4.75349426269531,
9.00399303436279, 5.48189449310303, 5.9071044921875, 5.30881881713867,
8.68398857116699, 8.68398857116699, 4.32339859008789, 8.57950687408447,
6.78787326812744, 8.68624305725098, 8.68624305725098, 12.9021902084351,
6.14854049682617, 6.71301507949829, 7.50605535507202, 7.33758926391602,
8.11069011688232, 7.33758926391602, 8.11069011688232, 8.11069011688232,
6.59299898147583, 5.92181205749512, 8.11069011688232, 7.33758926391602,
9.29954528808594, 7.33758926391602, 8.31999015808105, 7.33758926391602,
6.59299898147583, 6.16447877883911, 5.83903217315674), ts1 = c(4.19949150085449,
2.46556353569031, 3.96805644035339, 9.05560302734375, 9.5199556350708,
1.18671488761902, 6.60286664962769, 9.5199556350708, 9.5199556350708,
9.5199556350708, 9.5199556350708, 9.5199556350708, 2.12847352027893,
9.05560302734375, 9.5199556350708, 9.05560302734375, 2.11432313919067,
6.49393510818481, -0.165110915899277, 7.78503036499023, -7.71160411834717,
-0.979450941085815, 4.96369075775146, 4.28496122360229, 4.28496122360229,
6.35976600646973, 3.02656149864197, 2.80754446983337, 5.94739389419556,
5.94739389419556, 8.70161914825439, 1.57025468349457, 5.08782005310059,
4.27688789367676, 9.5199556350708, 8.49832916259766, 9.5199556350708,
8.49832916259766, 8.49832916259766, 9.05560302734375, 6.33359289169312,
8.49832916259766, 9.5199556350708, 7.99740839004517, 9.5199556350708,
2.12847352027893, 9.5199556350708, 9.05560302734375, 2.67069268226624,
7.33829879760742), ts2 = c(9.89923763275146, 10.9084701538086,
9.61682415008545, 13.6253662109375, 13.8121919631958, 6.19518041610718,
9.40560817718506, 13.8121919631958, 13.8121919631958, 13.8121919631958,
13.8121919631958, 13.8121919631958, 10.3912172317505, 13.6253662109375,
13.8121919631958, 13.6253662109375, 9.77112770080566, 11.5460777282715,
8.18180465698242, 12.9412984848022, 2.54625177383423, 8.29829216003418,
10.6650953292847, 10.1770324707031, 10.1770324707031, 12.4333782196045,
8.98324680328369, 8.45312309265137, 9.23384857177734, 9.23384857177734,
11.371600151062, 8.09108352661133, 12.0714511871338, 11.385799407959,
13.8121919631958, 13.912787437439, 13.8121919631958, 13.912787437439,
13.912787437439, 13.6253662109375, 12.0018119812012, 13.912787437439,
13.8121919631958, 14.0190010070801, 13.8121919631958, 10.3912172317505,
13.8121919631958, 13.6253662109375, 8.53981018066406, 12.7294788360596
), ts3 = c(17.718994140625, 21.1172523498535, 17.8669090270996,
23.1215572357178, 22.9536685943604, 15.3891229629517, 15.7000684738159,
22.9536685943604, 22.9536685943604, 22.9536685943604, 22.9536685943604,
22.9536685943604, 20.1229286193848, 23.1215572357178, 22.9536685943604,
23.1215572357178, 19.8251171112061, 19.3250198364258, 16.8351039886475,
22.2966594696045, 14.6743259429932, 17.1554985046387, 20.1656894683838,
20.0012702941895, 20.0012702941895, 23.2738876342773, 18.6255321502686,
16.2553405761719, 16.551155090332, 16.551155090332, 17.6266174316406,
16.1711521148682, 22.280725479126, 21.450382232666, 22.9536685943604,
23.5616970062256, 22.9536685943604, 23.5616970062256, 23.5616970062256,
23.1215572357178, 22.1113948822021, 23.5616970062256, 22.9536685943604,
23.5085678100586, 22.9536685943604, 20.1229286193848, 22.9536685943604,
23.1215572357178, 16.3595314025879, 22.7737102508545), ts4 = c(11.661883354187,
12.7669324874878, 11.6320190429688, 17.2357921600342, 17.4911460876465,
9.09537506103516, 12.179615020752, 17.4911460876465, 17.4911460876465,
17.4911460876465, 17.4911460876465, 17.4911460876465, 12.0781927108765,
17.2357921600342, 17.4911460876465, 17.2357921600342, 11.9486837387085,
13.7441387176514, 8.9575023651123, 15.9984045028687, 4.02816677093506,
9.12790489196777, 13.0505475997925, 12.842321395874, 12.842321395874,
14.8937959671021, 11.5566177368164, 10.0515727996826, 12.2921047210693,
12.2921047210693, 14.2251281738281, 9.64802074432373, 14.6072359085083,
13.7993869781494, 17.4911460876465, 17.0232067108154, 17.4911460876465,
17.0232067108154, 17.0232067108154, 17.2357921600342, 15.045259475708,
17.0232067108154, 17.4911460876465, 16.7633666992188, 17.4911460876465,
12.0781927108765, 17.4911460876465, 17.2357921600342, 10.0954942703247,
15.9187803268433), ps1sq = c(26.5076465606689, 22.2693958282471,
63.1422576904297, 112.398139953613, 126.182060241699, 83.3481597900391,
160.11540222168, 126.182060241699, 126.182060241699, 126.182060241699,
126.182060241699, 126.182060241699, 35.2550506591797, 112.398139953613,
126.182060241699, 112.398139953613, 63.3266563415527, 82.4000778198242,
18.478443145752, 68.4726028442383, 10.5714654922485, 20.3456344604492,
40.2613716125488, 44.3825721740723, 44.3825721740723, 22.58620262146,
39.5463447570801, 40.1031150817871, 107.331176757812, 107.331176757812,
350.305908203125, 32.8693962097168, 62.8768272399902, 82.7779006958008,
126.182060241699, 109.109313964844, 126.182060241699, 109.109313964844,
109.109313964844, 112.398139953613, 84.4768295288086, 109.109313964844,
126.182060241699, 122.418785095215, 126.182060241699, 35.2550506591797,
126.182060241699, 112.398139953613, 36.7173538208008, 91.480094909668
), ps2sq = c(27.3646068572998, 23.695915222168, 59.560977935791,
18.9136600494385, 20.1265487670898, 91.6154174804688, 70.2537155151367,
20.1265487670898, 20.1265487670898, 20.1265487670898, 20.1265487670898,
20.1265487670898, 47.2242088317871, 18.9136600494385, 20.1265487670898,
18.9136600494385, 38.5618858337402, 56.9987602233887, 31.6457366943359,
31.0436763763428, 9.54527759552002, 44.4674682617188, 19.5158863067627,
37.4422874450684, 37.4422874450684, 16.5555210113525, 40.439151763916,
32.6289215087891, 73.1417770385742, 73.1417770385742, 141.566955566406,
30.1786651611328, 28.5986976623535, 37.5058479309082, 20.1265487670898,
28.0557479858398, 20.1265487670898, 28.0557479858398, 28.0557479858398,
18.9136600494385, 20.3749599456787, 28.0557479858398, 20.1265487670898,
35.8471832275391, 20.1265487670898, 47.2242088317871, 20.1265487670898,
18.9136600494385, 31.1822872161865, 19.5749683380127), ps3sq =
c(24.5653991699219,
12.27476978302, 36.1357040405273, 0.72475278377533, 0.666339039802551,
64.6101531982422, 30.9392681121826, 0.666339039802551, 0.666339039802551,
0.666339039802551, 0.666339039802551, 0.666339039802551, 36.2002906799316,
0.72475278377533, 0.666339039802551, 0.72475278377533, 11.9318141937256,
28.2917289733887, 55.614875793457, 11.1645088195801, 43.7546501159668,
126.437408447266, 4.82320165634155, 28.063304901123, 28.063304901123,
2.6669340133667, 30.3901672363281, 46.0446548461914, 20.552619934082,
20.552619934082, 18.6443767547607, 50.5468521118164, 5.39163303375244,
7.55398797988892, 0.666339039802551, 2.17771244049072, 0.666339039802551,
2.17771244049072, 2.17771244049072, 0.72475278377533, 1.93400263786316,
2.17771244049072, 0.666339039802551, 3.42490386962891, 0.666339039802551,
36.2002906799316, 0.666339039802551, 0.72475278377533, 45.9697532653809,
1.46579575538635), ps4sq = c(32.1111907958984, 23.2654228210449,
54.7733688354492, 43.4676361083984, 53.840217590332, 99.6012649536133,
108.074615478516, 53.840217590332, 53.840217590332, 53.840217590332,
53.840217590332, 53.840217590332, 69.2222366333008, 43.4676361083984,
53.840217590332, 43.4676361083984, 49.811279296875, 70.2821273803711,
22.5957069396973, 81.071891784668, 30.0511665344238, 34.8938827514648,
28.183557510376, 75.4116592407227, 75.4116592407227, 18.6917762756348,
73.6079406738281, 46.0752220153809, 75.4508209228516, 75.4508209228516,
166.466506958008, 37.8045501708984, 45.0645713806152, 56.3408660888672,
53.840217590332, 65.7832946777344, 53.840217590332, 65.7832946777344,
65.7832946777344, 43.4676361083984, 35.0678596496582, 65.7832946777344,
53.840217590332, 86.4815444946289, 53.840217590332, 69.2222366333008,
53.840217590332, 43.4676361083984, 38.0007972717285, 34.094295501709
), ts1sq = c(17.6357288360596, 6.07900333404541, 15.7454719543457,
82.0039443969727, 90.6295547485352, 1.40829217433929, 43.5978469848633,
90.6295547485352, 90.6295547485352, 90.6295547485352, 90.6295547485352,
90.6295547485352, 4.53039932250977, 82.0039443969727, 90.6295547485352,
82.0039443969727, 4.47036218643188, 42.1711921691895, 0.0272616147994995,
60.6066970825195, 59.4688377380371, 0.95932412147522, 24.6382255554199,
18.3608932495117, 18.3608932495117, 40.4466247558594, 9.16007423400879,
7.88230609893799, 35.3714942932129, 35.3714942932129, 75.7181777954102,
2.46569967269897, 25.8859119415283, 18.2917709350586, 90.6295547485352,
72.2215957641602, 90.6295547485352, 72.2215957641602, 72.2215957641602,
82.0039443969727, 40.1143989562988, 72.2215957641602, 90.6295547485352,
63.9585418701172, 90.6295547485352, 4.53039932250977, 90.6295547485352,
82.0039443969727, 7.13259935379028, 53.8506278991699), ts2sq =
c(97.9949035644531,
118.994720458984, 92.4833068847656, 185.650604248047, 190.776641845703,
38.3802604675293, 88.465461730957, 190.776641845703, 190.776641845703,
190.776641845703, 190.776641845703, 190.776641845703, 107.977394104004,
185.650604248047, 190.776641845703, 185.650604248047, 95.4749374389648,
133.311904907227, 66.9419250488281, 167.477203369141, 6.48339796066284,
68.8616561889648, 113.744255065918, 103.571990966797, 103.571990966797,
154.588897705078, 80.6987228393555, 71.4552917480469, 85.2639617919922,
85.2639617919922, 129.313293457031, 65.4656295776367, 145.719940185547,
129.636428833008, 190.776641845703, 193.565658569336, 190.776641845703,
193.565658569336, 193.565658569336, 185.650604248047, 144.043487548828,
193.565658569336, 190.776641845703, 196.53239440918, 190.776641845703,
107.977394104004, 190.776641845703, 185.650604248047, 72.9283599853516,
162.039627075195), ts3sq = c(313.962768554688, 445.938354492188,
319.226440429688, 534.606384277344, 526.870910644531, 236.825103759766,
246.492156982422, 526.870910644531, 526.870910644531, 526.870910644531,
526.870910644531, 526.870910644531, 404.932250976562, 534.606384277344,
526.870910644531, 534.606384277344, 393.035278320312, 373.456390380859,
283.420715332031, 497.141021728516, 215.335845947266, 294.311126708984,
406.655029296875, 400.050811767578, 400.050811767578, 541.673828125,
346.910461425781, 264.236083984375, 273.940734863281, 273.940734863281,
310.697631835938, 261.506164550781, 496.430725097656, 460.118896484375,
526.870910644531, 555.153564453125, 526.870910644531, 555.153564453125,
555.153564453125, 534.606384277344, 488.913787841797, 555.153564453125,
526.870910644531, 552.652770996094, 526.870910644531, 404.932250976562,
526.870910644531, 534.606384277344, 267.63427734375, 518.641906738281
), ts4sq = c(135.999526977539, 162.994567871094, 135.303863525391,
297.072540283203, 305.940185546875, 82.7258453369141, 148.343017578125,
305.940185546875, 305.940185546875, 305.940185546875, 305.940185546875,
305.940185546875, 145.882736206055, 297.072540283203, 305.940185546875,
297.072540283203, 142.771041870117, 188.901351928711, 80.2368469238281,
255.948944091797, 16.2261276245117, 83.3186492919922, 170.316787719727,
164.925216674805, 164.925216674805, 221.825164794922, 133.555419921875,
101.034118652344, 151.095840454102, 151.095840454102, 202.354278564453,
93.0843048095703, 213.371337890625, 190.423080444336, 305.940185546875,
289.789581298828, 305.940185546875, 289.789581298828, 289.789581298828,
297.072540283203, 226.359832763672, 289.789581298828, 305.940185546875,
281.010467529297, 305.940185546875, 145.882736206055, 305.940185546875,
297.072540283203, 101.919006347656, 253.407562255859), pdnsty =
c(0.616999983787537,
0.0850000008940697, 0.068000003695488, 0.025000000372529, 0.0549999997019768,
0.0230000000447035, 0.133000001311302, 0.0549999997019768, 0.0549999997019768,
0.0549999997019768, 0.0549999997019768, 0.0549999997019768, 0.25900000333786,
0.025000000372529, 0.0549999997019768, 0.025000000372529, 0.0140000004321337,
0.14300000667572, 0.140000000596046, 0.777999997138977, 0.0329999998211861,
0.316000014543533, 0.0179999992251396, 0.105999998748302, 0.105999998748302,
0.046000000089407, 0.108000002801418, 0.310999989509583, 0.101000003516674,
0.101000003516674, 0.14300000667572, 0.168999999761581, 0.0439999997615814,
0.0379999987781048, 0.0549999997019768, 0.063000001013279, 0.0549999997019768,
0.063000001013279, 0.063000001013279, 0.025000000372529, 0.0640000030398369,
0.063000001013279, 0.0549999997019768, 0.209000006318092, 0.0549999997019768,
0.25900000333786, 0.0549999997019768, 0.025000000372529, 0.257999986410141,
0.0469999983906746), portsML = c(0.0900330692529678, 0.0604440234601498,
0.168490216135979, 0.275995850563049, 0.269018620252609, 0.175392478704453,
0.0350189469754696, 0.269018620252609, 0.269018620252609, 0.269018620252609,
0.269018620252609, 0.269018620252609, 0.11026918143034, 0.275995850563049,
0.269018620252609, 0.275995850563049, 0.145082741975784, 0.00440915673971176,
0.426146239042282, 0.0686663240194321, 0.103511147201061, 0.289726078510284,
0.234196603298187, 0.123688526451588, 0.123688526451588, 0.315173029899597,
0.112561739981174, 0.0461684986948967, 0.179993003606796, 0.179993003606796,
0.0438785217702389, 0.096462681889534, 0.0934395045042038, 0.121217466890812,
0.269018620252609, 0.212490051984787, 0.269018620252609, 0.212490051984787,
0.212490051984787, 0.275995850563049, 0.162760972976685, 0.212490051984787,
0.269018620252609, 0.270619571208954, 0.269018620252609, 0.11026918143034,
0.269018620252609, 0.275995850563049, 0.108705826103687, 0.196496397256851
), cities500k = c(0.0360943526029587, 0.0577861145138741, 0.183606043457985,
0.150749072432518, 0.185974538326263, 0.0923599153757095, 0.353672504425049,
0.185974538326263, 0.185974538326263, 0.185974538326263, 0.185974538326263,
0.185974538326263, 0.0887016654014587, 0.150749072432518, 0.185974538326263,
0.150749072432518, 0.144800990819931, 0.00326321297325194, 0.0622526630759239,
0.00816718116402626, 0.181859150528908, 0.163181975483894, 0.204970955848694,
0.129742562770844, 0.129742562770844, 0.0783679932355881, 0.0559677332639694,
0.0293320622295141, 0.248573184013367, 0.248573184013367, 0.174525216221809,
0.092569001019001, 0.176346719264984, 0.16088992357254, 0.185974538326263,
0.280431807041168, 0.185974538326263, 0.280431807041168, 0.280431807041168,
0.150749072432518, 0.088722825050354, 0.280431807041168, 0.185974538326263,
0.189705356955528, 0.185974538326263, 0.0887016654014587, 0.185974538326263,
0.150749072432518, 0.0712414756417274, 0.0842432081699371), rentedland
= c(0.571943998336792,
0, 0.5929936170578, 0, 0, 0.755691230297089, 0.440930217504501,
0, 0, 0, 0.229885056614876, 0, 0, 0, 0, 0, 0.890581607818604,
0.212423488497734, 0.386227518320084, 0, 0.11130790412426, 0.483032256364822,
0.444395005702972, 0, 0, 0.253378361463547, 0, 0.10909091681242,
0.181818187236786, 0.666666686534882, 0, 0.94951194524765, 0.846153855323792,
0.403846144676208, 0, 0, 0.155963316559792, 0, 0, 0.408163279294968,
0.699570834636688, 0, 0, 0, 0, 0, 0.0476190522313118, 0, 0, 0
), subsidies1 = c(361.835754394531, 0, 368.242034912109, 345.636352539062,
701.746032714844, 488.922821044922, 344.918609619141, 790.392150878906,
795.3125, 631.666687011719, 193.563217163086, 565.75, 0, 577.586181640625,
395.681823730469, 192, 371.963653564453, 9.9977331161499, 310.838317871094,
905.764709472656, 1745.76293945312, 359.003814697266, 163.204330444336,
427.94970703125, 204.842727661133, 52.2592887878418, 0, 0, 3022.24243164062,
80.2666702270508, 445.366577148438, 925.681640625, 824.769226074219,
625.192321777344, 850.441162109375, 280.891723632812, 619.266052246094,
333.962249755859, 376.304351806641, 317.551025390625, 166.652359008789,
171.224487304688, 526.119445800781, 253.191497802734, 334.470581054688,
107.277839660645, 431.428588867188, 0, 107.245544433594, 339.701507568359
), elevmean = c(0.121736958622932, 0.46412268280983, 0.344255149364471,
0.466430068016052, 0.43000802397728, 1.15364873409271, 0.0955904126167297,
0.43000802397728, 0.43000802397728, 0.43000802397728, 0.43000802397728,
0.43000802397728, 0.370405077934265, 0.466430068016052, 0.43000802397728,
0.466430068016052, 0.849120080471039, 0.0433186627924442, 0.335433751344681,
0.271958351135254, 0.125564843416214, 0.376024007797241, 0.815701544284821,
0.525435268878937, 0.525435268878937, 0.62959760427475, 0.518330037593842,
0.00362438289448619, 0.628515422344208, 0.628515422344208, 0.274942100048065,
0.0728112533688545, 0.496583759784698, 0.739268243312836, 0.43000802397728,
0.321640431880951, 0.43000802397728, 0.321640431880951, 0.321640431880951,
0.466430068016052, 0.585907399654388, 0.321640431880951, 0.43000802397728,
0.147326037287712, 0.43000802397728, 0.370405077934265, 0.43000802397728,
0.466430068016052, 0.0183117985725403, 0.414920538663864), elevrange =
c(0.180000007152557,
1.99300003051758, 0.611000001430511, 2.35199999809265, 2.29999995231628,
2.94199991226196, 0.354999989271164, 2.29999995231628, 2.29999995231628,
2.29999995231628, 2.29999995231628, 2.29999995231628, 2.01799988746643,
2.35199999809265, 2.29999995231628, 2.35199999809265, 1.7389999628067,
0.160999998450279, 0.314000010490417, 1.76300001144409, 0.17399999499321,
0.653999984264374, 1.63399994373322, 2.19099998474121, 2.19099998474121,
1.14100003242493, 1.34800004959106, 0.00899999961256981, 2.41300010681152,
2.41300010681152, 0.787999987602234, 0.26800000667572, 1.92200005054474,
2.02600002288818, 2.29999995231628, 1.05099999904633, 2.29999995231628,
1.05099999904633, 1.05099999904633, 2.35199999809265, 2.35999989509583,
1.05099999904633, 2.29999995231628, 0.772000014781952, 2.29999995231628,
2.01799988746643, 2.29999995231628, 2.35199999809265, 0.0649999976158142,
1.75399994850159), t_gravel = c(4.58953237533569, 13.3146963119507,
10.0136280059814, 13.8894920349121, 13.9366893768311, 13.5653190612793,
7.71220588684082, 13.9366893768311, 13.9366893768311, 13.9366893768311,
13.9366893768311, 13.9366893768311, 11.4818019866943, 13.8894920349121,
13.9366893768311, 13.8894920349121, 13.4321727752686, 5.71388387680054,
8.03888702392578, 9.01077747344971, 4.58924961090088, 8.14134693145752,
11.8983144760132, 9.96716785430908, 9.96716785430908, 11.1739711761475,
10.4019403457642, 5.16821479797363, 10.7357034683228, 10.7357034683228,
9.23897457122803, 4.3336238861084, 10.9520101547241, 12.9722995758057,
13.9366893768311, 13.1780118942261, 13.9366893768311, 13.1780118942261,
13.1780118942261, 13.8894920349121, 12.7335777282715, 13.1780118942261,
13.9366893768311, 12.315260887146, 13.9366893768311, 11.4818019866943,
13.9366893768311, 13.8894920349121, 6.68424606323242, 14.101095199585
), t_ph_h2o = c(6.07352828979492, 6.72695684432983, 5.60523176193237,
6.13967752456665, 6.86059141159058, 7.40929126739502, 5.68151950836182,
6.86059141159058, 6.86059141159058, 6.86059141159058, 6.86059141159058,
6.86059141159058, 6.51894521713257, 6.13967752456665, 6.86059141159058,
6.13967752456665, 6.98909568786621, 5.5628228187561, 6.68793487548828,
6.57724285125732, 4.67033195495605, 6.32772016525269, 6.4612717628479,
6.73934555053711, 6.73934555053711, 6.80293703079224, 6.17414236068726,
7.03696584701538, 5.93052577972412, 5.93052577972412, 5.43228578567505,
5.5989408493042, 6.86088180541992, 6.68706750869751, 6.86059141159058,
6.00043678283691, 6.86059141159058, 6.00043678283691, 6.00043678283691,
6.13967752456665, 6.89467239379883, 6.00043678283691, 6.86059141159058,
6.81896543502808, 6.86059141159058, 6.51894521713257, 6.86059141159058,
6.13967752456665, 5.63159275054932, 6.13170003890991), t_silt =
c(34.2329025268555,
33.4969100952148, 34.4774589538574, 27.8914813995361, 31.9258117675781,
39.6254501342773, 34.7939414978027, 31.9258117675781, 31.9258117675781,
31.9258117675781, 31.9258117675781, 31.9258117675781, 26.6626663208008,
27.8914813995361, 31.9258117675781, 27.8914813995361, 29.7444763183594,
21.3432540893555, 37.4038734436035, 28.1513748168945, 19.4936828613281,
33.5968360900879, 32.8024406433105, 33.313850402832, 33.313850402832,
28.3197917938232, 33.3154563903809, 38.103458404541, 36.0389099121094,
36.0389099121094, 34.9229164123535, 26.5577545166016, 30.9245643615723,
31.1334323883057, 31.9258117675781, 27.1493148803711, 31.9258117675781,
27.1493148803711, 27.1493148803711, 27.8914813995361, 31.3038387298584,
27.1493148803711, 31.9258117675781, 31.6541061401367, 31.9258117675781,
26.6626663208008, 31.9258117675781, 27.8914813995361, 15.6523361206055,
27.803352355957), t_sand = c(47.0063323974609, 37.0355186462402,
45.8286781311035, 36.0810203552246, 39.9931793212891, 39.3664970397949,
46.2948226928711, 39.9931793212891, 39.9931793212891, 39.9931793212891,
39.9931793212891, 39.9931793212891, 49.3508529663086, 36.0810203552246,
39.9931793212891, 36.0810203552246, 39.2436943054199, 65.7813262939453,
35.8039131164551, 51.2884674072266, 66.2952728271484, 46.6789817810059,
41.4505424499512, 44.4590721130371, 44.4590721130371, 48.7276763916016,
43.3654098510742, 33.999683380127, 43.040699005127, 43.040699005127,
43.2519073486328, 59.4827156066895, 43.8675765991211, 41.7124671936035,
39.9931793212891, 34.94921875, 39.9931793212891, 34.94921875,
34.94921875, 36.0810203552246, 39.1853942871094, 34.94921875,
39.9931793212891, 39.8589019775391, 39.9931793212891, 49.3508529663086,
39.9931793212891, 36.0810203552246, 75.7048721313477, 33.5687866210938
), AT = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), BE = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0), DE = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), DK = c(0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0), ES = c(0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), RO = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0), SI = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), SK = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0), b48 = c(70, 2.70000004768372, 63.9000015258789,
5.5, 6.30000019073486, 8.80000019073486, 48.0800018310547, 5.09999990463257,
6.40000009536743, 6, 6.69999980926514, 4, 6.30000019073486, 5.80000019073486,
8.80000019073486, 2, 13, 0.5, 10.25, 34, 65.2300033569336, 37.7799987792969,
74.9400024414062, 31.0200004577637, 20.0300006866455, 70.7200012207031,
40, 4.90000009536743, 13.5, 5, 26.8700008392334, 3, 2, 3.09999990463257,
6.80000019073486, 15.6999998092651, 9.19999980926514, 5.30000019073486,
4.59999990463257, 17.3999996185303, 7, 4.90000009536743, 13.3999996185303,
2.34999990463257, 8.5, 24.8700008392334, 4, 1.39999997615814,
34.7799987792969, 6.69999980926514), b50 = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34.2400016784668, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0), irrigation = c(0, 100, 0, 5.45454584062099,
7.9365074634552, 89.3392562866211, 0, 17.6470592617989, 0, 0,
65.5172407627106, 0, 61.904764175415, 34.4827562570572, 7.95454531908035,
75, 0, 0, 0, 0, 0, 0, 5.26393800973892, 0, 0, 0, 0, 0, 0, 0,
0, 0, 74.6153831481934, 84.6153914928436, 0, 5.09554147720337,
0, 0, 0, 21.0884347558022, 18.4549376368523, 6.1224490404129,
25.3731369972229, 2.12765969336033, 0, 84.3988716602325, 0, 0,
0, 100), awc_class = c(106.228088378906, 78.2306137084961, 80.9311141967773,
32.4921531677246, 54.8475151062012, 80.6665878295898, 116.331588745117,
54.8475151062012, 54.8475151062012, 54.8475151062012, 54.8475151062012,
54.8475151062012, 56.3101806640625, 32.4921531677246, 54.8475151062012,
32.4921531677246, 59.3034172058105, 101.193893432617, 96.5840377807617,
54.2786560058594, 87.1388244628906, 66.1907730102539, 57.205738067627,
55.4114303588867, 55.4114303588867, 80.9288787841797, 63.6008758544922,
150, 30.3404140472412, 30.3404140472412, 19.8318557739258, 104.236854553223,
79.2445755004883, 57.0045547485352, 54.8475151062012, 34.320426940918,
54.8475151062012, 34.320426940918, 34.320426940918, 32.4921531677246,
65.1337509155273, 34.320426940918, 54.8475151062012, 73.6748657226562,
54.8475151062012, 56.3101806640625, 54.8475151062012, 32.4921531677246,
127.726959228516, 27.9528160095215), sys02 = c(18.8571434020996,
303.529418945312, 30.2469139099121, 104.305557250977, 86.4935073852539,
51.25, 83.0927810668945, 453.118286132812, 42.5, 104.305557250977,
48.461540222168, 86.4935073852539, 55.1851844787598, 104.305557250977,
104.305557250977, 185.277770996094, 17.9775276184082, 25.2777786254883,
64, 21.6666660308838, 30, 24.2372875213623, 47.0285720825195,
16.1904754638672, 33.75, 22.5423736572266, 10.2857141494751,
39.230770111084, 6.06741571426392, 1, 28.3255805969238, 21.6000003814697,
69.2592620849609, 86.6666641235352, 48.5185203552246, 44.4186058044434,
48.6538467407227, 437.105255126953, 437.105255126953, 19.1666660308838,
48.461540222168, 437.105255126953, 48.6538467407227, 453.118286132812,
48.6538467407227, 14.2857141494751, 453.118286132812, 453.118286132812,
95.2380981445312, 63), se025 = c(163.529998779297, 2.70000004768372,
157, 5.5, 6.30000019073486, 36.0200004577637, 86, 5.09999990463257,
6.40000009536743, 6, 8.69999980926514, 4, 6.30000019073486, 5.80000019073486,
8.80000019073486, 2, 118.809997558594, 44.1100006103516, 16.7000007629395,
34, 73.4000015258789, 73.0800018310547, 134.880004882812, 31.0200004577637,
20.0300006866455, 94.7200012207031, 40, 5.5, 16.5, 15, 26.8700008392334,
59.4199981689453, 13, 5.19999980926514, 6.80000019073486, 15.6999998092651,
10.8999996185303, 5.30000019073486, 4.59999990463257, 29.3999996185303,
23.2999992370605, 4.90000009536743, 13.3999996185303, 2.34999990463257,
8.5, 24.8700008392334, 4.19999980926514, 1.39999997615814, 34.7799987792969,
6.69999980926514)), .Names = c("LnALVperHA", "ps1", "ps2", "ps3",
"ps4", "ts1", "ts2", "ts3", "ts4", "ps1sq", "ps2sq", "ps3sq",
"ps4sq", "ts1sq", "ts2sq", "ts3sq", "ts4sq", "pdnsty", "portsML",
"cities500k", "rentedland", "subsidies1", "elevmean", "elevrange",
"t_gravel", "t_ph_h2o", "t_silt", "t_sand", "AT", "BE", "DE",
"DK", "ES", "FI", "FR", "GR", "IE", "IT", "LU", "NL", "PT", "SE",
"WDE", "EDE", "UK", "CY", "BG", "CZ", "EE", "HU", "LT", "LV",
"PL", "RO", "SI", "SK", "b48", "b50", "irrigation", "awc_class",
"sys02", "se025"), row.names = c("2", "3", "4", "5", "6", "7",
"8", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
"21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31",
"32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42",
"43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53"
), class = "data.frame")
2015-08-14 14:58 GMT+02:00 PIKAL Petr <petr.pikal at precheza.cz>:
>
> Hi Janka
>
>
>
> Sorry, but we are limited in connecting to web services so I am not able to restore your data and see your code. Result of dput(somedata) coppied to email is preferable for sharing data and code can be copied to email too. But do not use HTML as it usually scrambles text.
>
>
>
> Answer in line
>
>
>
> From: Janka Vanschoenwinkel [mailto:janka.vanschoenwinkel at uhasselt.be]
> Sent: Friday, August 14, 2015 2:17 PM
> To: Thierry Onkelinx; PIKAL Petr
> Cc: r-help at r-project.org
> Subject: Re: [R] cut variable within a loop
>
>
>
> Hi Thierry and Petr,
>
>
>
> I really appreciate the comments you already gave. Thank you very much for that.
>
>
>
> Below you can find a link to the data and the code. Hopefully this helps in spotting the error.
>
>
>
> I still think the issue is that the cut2 function only accepts numbers, and not an "i" that refers to the number at the start of the loop. To answer Petr his question, yes, column 3 and 4 are NA (these are the columns of the second interval). But I don't really understand your point so could you clarify this please?
>
>
>
> If you use NA as a number of intervals you will get such errors
>
>
>
> k<-c(2,4,NA,5)
>
> ii<-vector(4, mode="list")
>
> for (i in 1:4) {
>
> ii[[i]] <- cut2(iris[,i], k[i])
>
> }
>
> Error in if (r[1] < cuts[1]) cuts <- c(r[1], cuts) :
>
> missing value where TRUE/FALSE needed
>
> for (i in 1:4) {
>
> ii[[i]] <- cut(iris[,i], k[i])
>
> }
>
> Error in cut.default(iris[, i], k[i]) : invalid number of intervals
>
>
>
> If you remove NA from k definition error is gone.
>
> k<-c(2,4,3,5)
>
> ii<-vector(4, mode="list")
>
>
>
> for (i in 1:4) {
>
> ii[[i]] <- cut(iris[,i], k[i])
>
> }
>
>
>
> You can try it yourself. The error is not related to cycle; whenever number of intervals in cut call is NA you always get an error.
>
>
>
> Cheers
>
> Petr
>
>
>
> https://drive.google.com/folderview?id=0By9u5m3kxn9yfkxxeVNMdnRQQXhoT05CRlJlZVBCWWF2NURMMTNmVFVFeXJXXzhlMWE4SUk&usp=sharing
>
>
>
> Thank you very much once again!
>
>
>
> Janka
>
>
>
>
>
>
>
> 2015-08-11 15:10 GMT+02:00 Thierry Onkelinx <thierry.onkelinx at inbo.be>:
>
> You'll need to send a reproducible example of the code. We can't run the code that you send. Hence it is hard to help you. See e.g. http://adv-r.had.co.nz/Reproducibility.html
>
>
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
> team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
> Kliniekstraat 25
> 1070 Anderlecht
> Belgium
>
> To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
> The plural of anecdote is not data. ~ Roger Brinner
> The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey
>
>
>
> 2015-08-11 14:57 GMT+02:00 Janka Vanschoenwinkel <janka.vanschoenwinkel at uhasselt.be>:
>
> Hi Thierry!
>
>
>
> Thanks for your answer. I tried this, but I get this error:
>
>
>
> "Error in cut.default(x, k2) : invalid number of intervals"
>
>
>
> Which is strange because I am not specifying intervals, but the number at where the sample has to be cut?
>
>
>
> Greetings from Belgium! :-)
>
>
>
> 2015-08-11 14:52 GMT+02:00 Thierry Onkelinx <thierry.onkelinx at inbo.be>:
>
> Dear Janka,
>
>
>
> You loop goes for 0 to 100. It should probably go from 1:99
>
>
>
> Best regards,
>
>
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
> team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
> Kliniekstraat 25
> 1070 Anderlecht
> Belgium
>
> To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
> The plural of anecdote is not data. ~ Roger Brinner
> The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey
>
>
>
> 2015-08-11 14:38 GMT+02:00 Janka Vanschoenwinkel <janka.vanschoenwinkel at uhasselt.be>:
>
> Dear list members,
>
> I have a loop where I want to do several calculations for different samples
> and save the results for each sample. These samples are for each loop
> different. I want to use the "i" in the loop to cut the samples.
>
> So for instance:
>
> - In loop 1 (i=1), I have a sample from 0-1 and a sample from 1-100.
> - In loop 2 (i=2), I have a sample from 0-2 and a sample from 2-100.
> - In loop 99 (i=99), I have a sample from 0-99 and a sample from 99-100.
>
> I built the following function, but there is *a problem with the cut2
> function* since it doesn't recognize the "i". Outside the lapply loop it
> works, but not inside the loop.
>
> Could somebody please help me with this problem? Thanks a lot!
>
>
> d=data.frame(MEt_Rainfed=rep(0,100),MEp_Rainfed=rep(0,100),MEt_Irrigation=rep(0,100),MEp_Irrigation=rep(0,100))
>
>
>
> o<-lapply(0:100, function(i){
>
>
>
> Alldata$irri=cut2(Alldata$irrigation,i)
>
> levels(Alldata$irri)<-c("0","1")
>
>
>
> Alldata_Rainfed<-subset(Alldata, irri == 0)
>
> Alldata_Irrigation<-subset(Alldata, irri == 1)
>
>
>
> #calculations per sample, then store all the values per i and per
> variable in a dataframe: (the calculations are not shown in this example)
>
>
>
> d[i, ] = c(MEt_Rainfed,MEp_Rainfed,MEt_Irrigation,MEp_Irrigation)
>
>
>
> })
>
>
>
> out<-as.data.frame(do.call(rbind, o))
>
>
> --
> P Please consider the environment before printing this e-mail
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
>
>
>
> --
>
>
>
> Mevrouw Janka Vanschoenwinkel
> Doctoraatsbursaal - PhD
> Milieueconomie - Environmental economics
>
> T +32(0)11 26 87 42 | GSM +32(0)476 28 21 40
>
> www.uhasselt.be/eec
>
> Universiteit Hasselt | Campus Diepenbeek
> Agoralaan Gebouw D | B-3590 Diepenbeek
> Kantoor F11
>
> Postadres: Universiteit Hasselt | Martelarenlaan 42 | B-3500 Hasselt
>
> P Please consider the environment before printing this e-mail
>
>
>
>
>
>
>
>
>
> --
>
>
>
> Mevrouw Janka Vanschoenwinkel
> Doctoraatsbursaal - PhD
> Milieueconomie - Environmental economics
>
> T +32(0)11 26 87 42 | GSM +32(0)476 28 21 40
>
> www.uhasselt.be/eec
>
> Universiteit Hasselt | Campus Diepenbeek
> Agoralaan Gebouw D | B-3590 Diepenbeek
> Kantoor F11
>
> Postadres: Universiteit Hasselt | Martelarenlaan 42 | B-3500 Hasselt
>
> P Please consider the environment before printing this e-mail
>
>
>
>
> ________________________________
> Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům.
> Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému.
> Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
> Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu.
>
> V případě, že je tento e-mail součástí obchodního jednání:
> - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
> - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou.
> - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech.
> - odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá.
>
> This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients.
> If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system.
> If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner.
> The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email.
>
> In case that this e-mail forms part of business dealings:
> - the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning.
> - if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation.
> - the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects.
> - the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.
--
Mevrouw Janka Vanschoenwinkel
Doctoraatsbursaal - PhD
Milieueconomie - Environmental economics
T +32(0)11 26 87 42 | GSM +32(0)476 28 21 40
www.uhasselt.be/eec
Universiteit Hasselt | Campus Diepenbeek
Agoralaan Gebouw D | B-3590 Diepenbeek
Kantoor F11
Postadres: Universiteit Hasselt | Martelarenlaan 42 | B-3500 Hasselt
P Please consider the environment before printing this e-mail
More information about the R-help
mailing list