[R] error in rownames

Adams, Jean jvadams at usgs.gov
Mon Sep 29 15:22:39 CEST 2014


Chris,

I think your best bet is to find someone locally that is familiar with R,
and show them this correspondence.  They will be able to help you post your
question so that you have the best chance of getting an answer.  Or,
perhaps, they will be able to answer the question themselves.

Jean

On Thu, Sep 25, 2014 at 10: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