[R] error in rownames

Chris Jackson-Jordan jacksonjordancm at gmail.com
Thu Sep 25 17:57:25 CEST 2014


Sorry to respond again so quickly, but is this what you meant?


y <- subset(training, select = c(ResponseSu))> x <- subset(training,
select = c(sinaspect, habitat, elevation, disttowat, disttoroad,
slope, cosaspect))> type.rf <- yai(x=x, y=y, method="randomForest",
rfMode="regression", ntree=20)> outfile <-
list(Type="RespSurf_Reg.asc")> xfile <-list(sinaspect="sinaspect.asc",
habitat="habitat.asc", elevation="elevation.asc",+
disttowat="disttowat.asc", disttoroad="disttoroad.asc",
slope="slope.asc",+ cosaspect="cosaspect.asc")> dput(training[1:60,
])structure(list(CID = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L), cosaspect = c(-0.546873, 0.333357, 0.796074, -0.906097,
0.546751, -0.903426, 0.55381, 0.761338, 0.858955, -0.784384,
0.790582, 0.0429794, 0.89785, 0.998368, 0.991524, -0.769041,
-0.104549, -0.565003, -0.56414, 0.432783, -0.652663, -0.477157,
-0.642625, 0.0719997, 0.0202113, -0.444488, -0.38204, -0.3565,
-0.199093, 0.545715, -0.99322, 0.852507, -0.524166, 0.999378,
-0.980175, -0.922242, -0.954118, -0.902187, -0.354786, 0.112082,
-0.198151, -0.502453, -0.676458, -0.0673507, -0.999526, -0.840507,
0.989883, -0.832413, -0.733279, -0.993005, -0.479475, -0.326237,
-0.848538, -0.546614, -0.986488, -0.948983, -0.993527, -0.964193,
-0.971359, -0.287455), disttoroad = c(368.767, 880.661, 563.239,
72.1515, 227.697, 313.486, 265.001, 227.697, 219.137, 518.349,
23.048, 10.3074, 41.2294, 103.074, 497.857, 494.968, 524.968,
674.01, 10.3074, 133.996, 10.3074, 10.3074, 10.3074, 20.6147,
226.058, 10.3074, 272.122, 226.762, 177.933, 204.075, 82.4589,
61.8442, 14.5768, 20.6147, 29.1536, 92.1918, 75.0387, 113.849,
133.996, 46.0959, 123.688, 120.645, 185.533, 133.996, 61.8442,
103.074, 120.203, 154.61, 138.671, 150.077, 51.5368, 190.058,
72.884, 20.6147, 115.24, 30.9221, 83.1006, 333.041, 30.9221,
288.606), disttowat = c(981.15, 1448.98, 729.496, 509.146, 171.549,
322.671, 566.998, 631.783, 783.359, 407.76, 1036.59, 352.264,
306.113, 235.27, 241.289, 269.769, 342.633, 660.476, 578.04,
1844.99, 1753.65, 408.801, 543.951, 756.661, 632.875, 540.031,
927.09, 1120.47, 1166.24, 65.9993, 474.586, 437.911, 162.974,
576.66, 557.932, 547.844, 793.667, 420.586, 208.708, 10.3074,
497.857, 383.595, 371.78, 130.379, 449.406, 111.014, 162.974,
393.574, 463.831, 360.021, 404.096, 43.7304, 140.195, 182.647,
277.343, 84.9967, 87.4609, 633.546, 60.1017, 42.4983), elevation = c(2000.9,
2198.18, 2194.78, 1863.8, 1902.25, 1867.29, 1943.94, 1912.35,
1920.11, 1870.94, 1914.56, 1904.4, 1900.92, 1893.94, 1888.02,
1889.71, 1890.95, 1894.32, 1896.11, 2011.99, 2025.01, 1902.45,
1901.99, 2030.09, 2038.39, 1910.48, 2054.46, 1918.92, 1951.15,
1941.24, 1853.78, 1863.76, 1875.9, 1863.6, 1864.91, 1864.18,
1872.85, 1866.81, 1863.06, 1896.47, 1863.95, 1873.13, 1873.44,
1888.06, 1874.35, 1888.06, 1911.09, 1872.43, 1854.83, 1866.98,
1876.95, 1875.88, 1875.19, 1888.27, 1900.82, 1870.49, 1903.17,
1871.52, 1902.28, 1862.18), habitat = c(14L, 1L, 9L, 2L, 5L,
2L, 5L, 1L, 1L, 2L, 1L, 4L, 10L, 8L, 2L, 2L, 2L, 2L, 4L, 10L,
5L, 4L, 4L, 3L, 5L, 4L, 3L, 3L, 7L, 6L, 2L, 2L, 2L, 13L, 2L,
2L, 2L, 2L, 2L, 11L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 10L, 2L, 2L, 2L, 2L, 2L), sinaspect = c(-0.837215,
-0.942801, -0.6052, 0.42307, -0.837295, -0.428745, -0.832643,
-0.648355, -0.512051, -0.620276, -0.612357, -0.999076, -0.440302,
-0.0571153, 0.129924, -0.6392, -0.99452, -0.825089, 0.825679,
-0.901498, -0.757648, 0.878818, 0.766181, -0.997405, -0.999796,
0.895785, 0.924146, 0.934295, 0.979981, -0.837971, 0.11625, -0.522717,
-0.851616, -0.0352723, 0.198133, -0.386614, -0.29943, -0.431345,
-0.934948, -0.993699, -0.980172, -0.864605, -0.736481, 0.997729,
-0.0307994, -0.541801, 0.141883, -0.554156, 0.679928, 0.118074,
-0.877556, -0.945288, -0.529134, -0.837385, -0.163837, -0.315329,
-0.113595, 0.265202, -0.237618, -0.957794), slope = c(28.8435,
2.74077, 34.8524, 0.151366, 18.6671, 0.132943, 17.6102, 16.0996,
9.36435, 0.452752, 1.9657, 0.996516, 1.74535, 0.148506, 0.0372119,
0.695029, 0.455934, 0.514605, 12.6356, 16.0089, 8.21627, 1.038,
0.498378, 3.6306, 4.11395, 10.3384, 15.5258, 16.5868, 30.8142,
11.3484, 0.041589, 0.102877, 0.277677, 0.642031, 0.663088, 0.289154,
1.05732, 0.216892, 0.233333, 0.248217, 0.176358, 0.193456, 0.245883,
0.108306, 0.583814, 0.106767, 0.102823, 0.395655, 1.33206, 0.243522,
0.811744, 0.116737, 0.573048, 0.672642, 0.415712, 0.396212, 0.447255,
0.13081, 0.410137, 0.727014), POINT_X = c(518112.161959, 517972.063651,
517506.021145, 514057.581202, 517528.545479, 514676.488847, 513464.270056,
513494.888654, 513586.036568, 515116.814902, 514135.06997, 519325.532909,
519683.204101, 519319.141302, 516830.545136, 516920.973864, 516979.229306,
517071.772928, 519951.348487, 515653.777436, 515800.193588, 520379.011629,
520642.986006, 519523.715662, 519637.527771, 521060.390222, 516952.842708,
517668.222196, 517617.227048, 520449.447941, 517052.212122, 514140.686317,
516431.927756, 514013.562097, 514243.405122, 514221.174814, 515311.187185,
514481.609078, 516589.086276, 517741.589283, 514186.085127, 515664.921099,
515733.804812, 517203.924014, 515751.253306, 517234.791292, 518427.782061,
515550.127549, 517048.546153, 514494.364954, 516677.023244, 516310.352775,
516408.158711, 517318.540292, 517974.751913, 515658.214168, 517623.031178,
514989.975043, 517581.921764, 516383.86435), POINT_Y = c(4808806.0847,
4810255.98377, 4811945.72636, 4812470.84981, 4812715.02483, 4813198.79081,
4813211.23833, 4813295.64352, 4813440.86864, 4813568.04148, 4813679.00767,
4813733.06168, 4814419.5912, 4814825.63894, 4816350.24526, 4816582.01425,
4816699.05741, 4817224.27439, 4817499.81568, 4817609.1733, 4817984.23946,
4818382.23486, 4818760.15577, 4819648.35709, 4819860.27227, 4819904.21184,
4820486.25819, 4820487.64551, 4820517.62914, 4820967.31897, 4809549.90161,
4812476.57785, 4813749.28092, 4812522.41608, 4812915.00417, 4812798.13954,
4813967.9282, 4813155.89553, 4811594.81676, 4817137.5718, 4812661.71143,
4813651.06428, 4813725.92053, 4816265.95688, 4813846.96134, 4816303.22503,
4819272.23858, 4813534.92529, 4809713.38594, 4813053.33525, 4813732.08346,
4813902.3087, 4813642.82751, 4816248.7419, 4817916.27765, 4813224.05382,
4818419.86058, 4813769.26218, 4818313.11043, 4811436.27069),
    ResponseSu = 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, 1.394676,
    1.435637, 1.449758, 1.461653, 1.471431, 1.475303, 1.475902,
    1.481716, 1.490055, 1.493364, 1.493391, 1.495781, 1.509532,
    1.51392, 1.519015, 1.522284, 1.52319, 1.525427, 1.527304,
    1.534297, 1.534883, 1.535686, 1.536898, 1.539433, 1.544022,
    1.553086, 1.555488, 1.581577, 1.585341, 1.585509)), .Names = c("CID",
"cosaspect", "disttoroad", "disttowat", "elevation", "habitat",
"sinaspect", "slope", "POINT_X", "POINT_Y", "ResponseSu"), row.names = c(NA,
60L), class = "data.frame")> AsciiGridImpute(type.rf, xfile, outfile)


On Thu, Sep 25, 2014 at 11:51 AM, Chris Jackson-Jordan <
jacksonjordancm at gmail.com> wrote:

> Thanks again for your help, I am obviously a novice programmer. That said,
> I think I am confused as to what you mean by reproducible code. Were the 20
> lines of code not reproducible? Also, what do you mean by the help for
> Ascii Grid Impute. I'm not able to find it online or within the R platform.
> Finally, I know that mapping to files on my PC is problematic, should I be
> attaching the files in my email? Like I said, this is all quite new to me.
> Sorry if my questions are painfully naive. I am hoping to get this project
> going but just can't get past this stumbling block. Thanks again for the
> help thus far.
>
> Chris
>
> On Thu, Sep 25, 2014 at 11:06 AM, Adams, Jean <jvadams at usgs.gov> wrote:
>
>> Chris,
>>
>> You are not making it easy for R help folks to help you.
>>
>> You need to supply *** reproducible *** code, so that folks can simply
>> copy and paste directly from your e-mail to R and reproduce the error that
>> you are getting.  Do you need a guide to follow?  See the first 60-some
>> lines of code provided in the example of the help for AsciiGridImpute,
>>      ?AsciiGridImpute
>> I can copy that code into R and make it run.  You need to do the same
>> thing in your e-mail.  Don't refer to directories on your PC.
>>
>> I submitted a simplified version of the code you shared (below), but ran
>> into an error because the *.asc files were not already created.  So, I
>> suggest that you insert some general code to get that done for your
>> example, and resubmit your question.
>>
>> Jean
>>
>>
>> training <- structure(list(CID = c(0L, 0L, 0L, 0L, 0L,
>> 0L, 0L, 0L, 0L, 0L,
>> 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), cosaspect = c(-0.402376,
>> -0.263312, -0.978401, 0.0364174, 0.975655, -0.954148, -0.982731,
>> 0.949282, -0.827262, -0.300375, -0.211474, -0.63658, 0.892831,
>> -0.0395686, 0.649339, 0.0129927, -0.428111, -0.970759, 0.891974,
>> -0.901187), disttoroad = c(475.928, 245.003, 671.958, 10.3074,
>> 384.839, 180.305, 620.157, 290.441, 587.61, 72.1515, 10.3074,
>> 43.7304, 20.6147, 10.3074, 428.717, 72.884, 106.121, 175.225,
>> 249.302, 30.9221), disttowat = c(535.685, 309.907, 291.536, 1039.97,
>> 258.507, 202.508, 387.315, 1233.18, 666.481, 457.721, 1553.81,
>> 679.505, 1115.53, 515.162, 692.974, 498.604, 204.075, 388.138,
>> 885.474, 343.097), elevation = c(1901.69, 1992.82, 1911.9, 1985.14,
>> 1979.67, 1870.83, 1909.5, 2111.45, 1913.09, 1922.76, 1996.68,
>> 2092.64, 2066.89, 1872.85, 2047.7, 1923.03, 1981.28, 1875.6,
>> 2074.82, 1866.82), habitat = c(2L, 5L, 2L, 10L, 1L, 2L, 2L, 3L,
>> 2L, 16L, 3L, 3L, 1L, 4L, 1L, 5L, 6L, 2L, 3L, 10L), sinaspect = c(0.915474,
>> -0.964711, 0.206717, 0.999337, 0.21931, -0.299336, -0.185039,
>> -0.314428, -0.561817, -0.953821, -0.977384, -0.771211, -0.450392,
>> -0.999217, -0.760499, 0.999916, 0.903726, -0.240057, -0.452087,
>> -0.433431), slope = c(0.768307, 11.4002, 1.34928, 3.42667, 19.6776,
>> 0.341443, 3.14869, 7.14637, 1.1572, 24.4974, 11.0014, 19.4188,
>> 16.3333, 5.23936, 9.95699, 17.1475, 21.374, 0.475218, 7.23375,
>> 0.29158), POINT_X = c(517098.970249, 517940.940865, 517526.253849,
>> 516073.554503, 516019.068701, 515506.165434, 517353.141738, 520076.487742,
>> 517973.141394, 516823.388106, 514784.035218, 518298.237046, 519796.43389,
>> 515714.490202, 518829.909017, 519385.491579, 518659.851297, 516654.780318,
>> 519063.701155, 516270.975247), POINT_Y = c(4818385.61487, 4816762.97919,
>> 4819015.00611, 4816604.93198, 4814958.09214, 4813316.65912, 4818923.42436,
>> 4819217.24161, 4820124.20539, 4814172.9439, 4815372.65581, 4816674.91138,
>> 4819393.11718, 4812616.30708, 4818780.85554, 4816287.01774, 4814503.57051,
>> 4813614.51134, 4818804.92703, 4812168.6041), ResponseSu = c(1.822784,
>> 398.591262, 5.565648, 69.106734, 235.114325, 2.162961, 8.170528,
>> 389.107013, 11.32454, 4880.467707, 192.215083, 160.17186, 91.843573,
>> 63.863233, 113.728819, 100.03871, 1288.273717, 14.032336, 141.478417,
>> 10.020201)), .Names = c("CID", "cosaspect", "disttoroad", "disttowat",
>> "elevation", "habitat", "sinaspect", "slope", "POINT_X", "POINT_Y",
>> "ResponseSu"), row.names = c(NA, 20L), class = "data.frame")
>>
>> library(yaImpute)
>>
>> y <- subset(training, select = c(ResponseSu))
>> x <- subset(training, select = c(sinaspect, habitat, elevation,
>> disttowat, disttoroad, slope, cosaspect))
>> type.rf <- yai(x=x, y=y, method="randomForest", rfMode="regression",
>> ntree=20)
>> outfile <- list(Type="RespSurf_Reg.asc")
>> xfile <-list(sinaspect="sinaspect.asc", habitat="habitat.asc",
>> elevation="elevation.asc",
>> disttowat="disttowat.asc", disttoroad="disttoroad.asc",
>> slope="slope.asc",
>> cosaspect="cosaspect.asc")
>>
>> # insert lines of code here to create the *.asc files
>> # see the example with the iris data in ?AsciiGridImpute
>>
>> AsciiGridImpute(type.rf, xfile, outfile)
>>
>>
>> On Mon, Sep 22, 2014 at 11:13 AM, Chris Jackson-Jordan <
>> jacksonjordancm at gmail.com> wrote:
>>
>>> Dear fellow R users,
>>>
>>> I am trying to run the random forest and Yaimpute packages in R to
>>> impute a grid to project in a gis. However, after running the
>>> imputation I keep getting an error in the rownames. This sounds simple
>>> enough, but I cannot figure out what these rownames are reffering to.
>>> Any ideas? I am fairly new to R so im sure it is an easy fix. Any help
>>> would be awesome.
>>>
>>> Thanks,
>>>
>>> Chris
>>>
>>>
>>> > y <- subset(training, select = c(ResponseSu)) > x <- subset(training,
>>> select = c(sinaspect, habitat, slope, elevation, cosaspect, disttoroad,
>>> disttowat)) > type.rf <- yai(x=x, y=y, method="randomForest",
>>> rfMode="regression", ntree= 2000) > outfile <- list(Type =
>>> "D:/R_Desktop_Data/RF_RespSurf/RespSurf_Reg.asc") > xfile
>>> <-list(sinaspect
>>>
>>> ="C:/Users/jacksonjordancm/Desktop/R_Desktop_Data/RF_NNimp/ModelI/ASCII_Files2/sinaspect.asc",
>>> habitat
>>>
>>> ="C:/Users/jacksonjordancm/Desktop/R_Desktop_Data/RF_NNimp/ModelI/ASCII_Files2/habitat.asc",
>>> elevation
>>>
>>> ="C:/Users/jacksonjordancm/Desktop/R_Desktop_Data/RF_NNimp/ModelI/ASCII_Files2/elevation.asc",
>>> disttowat
>>>
>>> ="C:/Users/jacksonjordancm/Desktop/R_Desktop_Data/RF_NNimp/ModelI/ASCII_Files2/disttowat.asc",
>>> disttoroad
>>>
>>> ="C:/Users/jacksonjordancm/Desktop/R_Desktop_Data/RF_NNimp/ModelI/ASCII_Files2/disttoroad.asc",
>>> slope
>>>
>>> ="C:/Users/jacksonjordancm/Desktop/R_Desktop_Data/RF_NNimp/ModelI/ASCII_Files2/slope.asc",
>>> cosaspect
>>>
>>> ="C:/Users/jacksonjordancm/Desktop/R_Desktop_Data/RF_NNimp/ModelI/ASCII_Files2/cosaspect.asc")
>>> > AsciiGridImpute(type.rf, xfile, outfile) Rows per dot: 19 Rows to do:
>>> 1900 ToDo:
>>>
>>> ....................................................................................................
>>> Done: . Error in `rownames<-`(`*tmp*`, value = c("23x0049", "23x0050",
>>> "23x0051", : attempt to set rownames on object with no dimensions
>>>
>>> here is an example of my training data
>>>
>>>
>>>  > dput(training[1:20, ])structure(list(CID = c(0L, 0L, 0L, 0L, 0L,
>>>
>>> 0L, 0L, 0L, 0L, 0L,
>>> 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), cosaspect = c(-0.402376,
>>> -0.263312, -0.978401, 0.0364174, 0.975655, -0.954148, -0.982731,
>>> 0.949282, -0.827262, -0.300375, -0.211474, -0.63658, 0.892831,
>>> -0.0395686, 0.649339, 0.0129927, -0.428111, -0.970759, 0.891974,
>>> -0.901187), disttoroad = c(475.928, 245.003, 671.958, 10.3074,
>>> 384.839, 180.305, 620.157, 290.441, 587.61, 72.1515, 10.3074,
>>> 43.7304, 20.6147, 10.3074, 428.717, 72.884, 106.121, 175.225,
>>> 249.302, 30.9221), disttowat = c(535.685, 309.907, 291.536, 1039.97,
>>> 258.507, 202.508, 387.315, 1233.18, 666.481, 457.721, 1553.81,
>>> 679.505, 1115.53, 515.162, 692.974, 498.604, 204.075, 388.138,
>>> 885.474, 343.097), elevation = c(1901.69, 1992.82, 1911.9, 1985.14,
>>> 1979.67, 1870.83, 1909.5, 2111.45, 1913.09, 1922.76, 1996.68,
>>> 2092.64, 2066.89, 1872.85, 2047.7, 1923.03, 1981.28, 1875.6,
>>> 2074.82, 1866.82), habitat = c(2L, 5L, 2L, 10L, 1L, 2L, 2L, 3L,
>>> 2L, 16L, 3L, 3L, 1L, 4L, 1L, 5L, 6L, 2L, 3L, 10L), sinaspect =
>>> c(0.915474,
>>> -0.964711, 0.206717, 0.999337, 0.21931, -0.299336, -0.185039,
>>> -0.314428, -0.561817, -0.953821, -0.977384, -0.771211, -0.450392,
>>> -0.999217, -0.760499, 0.999916, 0.903726, -0.240057, -0.452087,
>>> -0.433431), slope = c(0.768307, 11.4002, 1.34928, 3.42667, 19.6776,
>>> 0.341443, 3.14869, 7.14637, 1.1572, 24.4974, 11.0014, 19.4188,
>>> 16.3333, 5.23936, 9.95699, 17.1475, 21.374, 0.475218, 7.23375,
>>> 0.29158), POINT_X = c(517098.970249, 517940.940865, 517526.253849,
>>> 516073.554503, 516019.068701, 515506.165434, 517353.141738,
>>> 520076.487742,
>>> 517973.141394, 516823.388106, 514784.035218, 518298.237046, 519796.43389,
>>> 515714.490202, 518829.909017, 519385.491579, 518659.851297,
>>> 516654.780318,
>>> 519063.701155, 516270.975247), POINT_Y = c(4818385.61487, 4816762.97919,
>>> 4819015.00611, 4816604.93198, 4814958.09214, 4813316.65912,
>>> 4818923.42436,
>>> 4819217.24161, 4820124.20539, 4814172.9439, 4815372.65581, 4816674.91138,
>>> 4819393.11718, 4812616.30708, 4818780.85554, 4816287.01774,
>>> 4814503.57051,
>>> 4813614.51134, 4818804.92703, 4812168.6041), ResponseSu = c(1.822784,
>>> 398.591262, 5.565648, 69.106734, 235.114325, 2.162961, 8.170528,
>>> 389.107013, 11.32454, 4880.467707, 192.215083, 160.17186, 91.843573,
>>> 63.863233, 113.728819, 100.03871, 1288.273717, 14.032336, 141.478417,
>>> 10.020201)), .Names = c("CID", "cosaspect", "disttoroad", "disttowat",
>>> "elevation", "habitat", "sinaspect", "slope", "POINT_X", "POINT_Y",
>>> "ResponseSu"), row.names = c(NA, 20L), class = "data.frame")>
>>> library("randomForest", lib.loc="~/RStudio/R/library")
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> 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.
>>>
>>
>>
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list