[R] How can I create a loop for this? Please help me
jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Fri Oct 5 20:03:57 CEST 2018
In addition to using plain text format when you post, please try to create a complete minimal example  that sets up a representative set of the variables you are using because the behavior of functions can change depending on what kind of data you are working with. For instance, so you have reason to believe that the number of columns will always divide out with no remainder? Why don't you split this data up before you create the one large SpatialPointsDataFrame? It is highly unusual to have multiple columns with the same names in any one data frame (it looks like you think two of each block of 12 columns will be named long and lat, but they all come from one source data frame).
 https://cran.r-project.org/web/packages/reprex/index.html (read the vignette)
On October 5, 2018 8:42:24 AM PDT, Bert Gunter <bgunter.4567 using gmail.com> wrote:
>1. As your query is about spatial data, you may do better posting (in
>text, **not** html, which often gets mangled on these plain text lists)
>the r-sig-geo list.
>2. These lists can help, but do not replace, your obligation to do your
>homework. There are many good R tutorials on the web that you can look
>for help. Some recommendations, by no means all that you may wish to
>can be found here:
>There are also both tutorials and "Vignettes" (the latter in the
>themselves) specifically for spatial data analysis and visualization.
>Searching on "R tutorial spatial data" brought up several.
>"The trouble with having an open mind is that people keep coming along
>sticking things into it."
>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>On Fri, Oct 5, 2018 at 8:12 AM Ivy Pieters <icwpieters using gmail.com>
>> Hey there,
>> I am very much a newbie in the R world. I have to work with R for my
>> internship. I really hope that someone can help me out here, since it
>> me ages to run and adjust the same script over and over again.
>> I have a SpatialPointsDataFrame table (sent2field2 using data) that I would
>> like to split into different SpatialPointsDataFrame tables. The first
>> needs to consist out of [1:13] columns, the second table needs to
>> of [,c(1,14:25)] the third needs to consist of [,c(1,26:37)]. The
>> the tables need to be Sent2Field2_1, Sent2Field2_2, Sent2Field2_3,
>> So only 1,2,3,4 etc need to change within the name. This loop needs
>> on until there are no columns left anymore in the dataset. Then the
>> step needs to add coordinates to the table (see script below). The
>> the tables need to be Sent2F2_1, Sent2F2_2, Sent2F2_3, etc etc… So
>> 1,2,3,4 etc need to change within the name. The last step projects
>> table with the added coordinates into a SpatialPointsDataFrame. See
>> script below: (up to now I am adjusting the names manually and
>> time after time, i am getting crazy, but I really don’t know how to
>> loop) For now the separate steps are working fine. I really hope
>> can help me out. Looking forward to anyones reply. Thank you already
>> Sent2Field2_1<-Sent2Field2 using data[,1:13]
>> coordinates(Sent2F2_1) <- ~long+lat
>> Sent2Field2_2<-Sent2Field2 using data[,c(1,14:25)]
>> coordinates(Sent2F2_2) <- ~long+lat
>> Sent2Field2_3<-Sent2Field2 using data[,c(1,26:37)]
>> coordinates(Sent2F2_3) <- ~long+lat
>> Sent2Field2_4<-Sent2Field2 using data[,c(1,38:49)]
>> coordinates(Sent2F2_4) <- ~long+lat
>> Sent2Field2_5<-Sent2Field2 using data[,c(1,50:61)]
>> coordinates(Sent2F2_5) <- ~long+lat
>> [[alternative HTML version deleted]]
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.
> [[alternative HTML version deleted]]
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.
Sent from my phone. Please excuse my brevity.
More information about the R-help