Hello,
I'm trying to subet my data based on long/lat. I have written a for loop
however I am not sure how to get R to name all my subsets different things.
Here is my code so far...
for(i in 0:31){
latl=38+(i*1)
latu=39+(i*1)
for(j in 0:33){
longl=(-72)+(j*1)
longu=(-71)+(j*1)
G$i$j-subset(G,
The standard way to do this is to use the cut function to define group
categories, and then manipulate data in lists of subsets using lapply function
and relatives. There are also tools such as the plyr package, data.table
package, sqldf package, and the new dplyr package.
If you want more
Here is one way by just truncating your data to integers based on what
you are doing:
# create some test data
n - 1000
G - data.frame(Lat = runif(n, 38, 50), Long = runif(n, -72, -65))
# add a 'key' for segment - based on truncating data
G$key - paste(as.integer(G$Lat), as.integer(G$Long),
Thank you very much !
--
View this message in context:
http://r.789695.n4.nabble.com/Automatically-naming-subsets-in-a-for-loop-tp4684518p4684524.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
4 matches
Mail list logo