[R] looping with paste

Sarah Goslee sarah.goslee at gmail.com
Mon Aug 22 22:43:40 CEST 2011


Juta,

On Mon, Aug 22, 2011 at 4:29 PM, Juta Kawalerowicz
<juta.kawalerowicz at stx.ox.ac.uk> wrote:
> Dear list,
>
> I have a spacialPolygonDataFrame where variables were unnecessarily imported as factors. So I am trying to unfactor variables from spatialPolygonDataFrame at data with a loop
>
>
> for (i in (1:length(names( spatialPolygonDataFrame)))){
>
>
> command<-paste("spatialPolygonDataFrame$names(spatialPolygonDataFrame at data[",i,"])<-as.character( spatialPolygonDataFrame$names( spatialPolygonDataFrame at data[",i,"])")
> command<-noquote(command)
> command
>
> }
>
>
> But I keep getting just a printout

Yeah, you're putting together a string, not actually running any commands.

Does this not work:

for (i in (1:length(names( spatialPolygonDataFrame)))){

spatialPolygonDataFrame$names(spatialPolygonDataFrame at data[i]) <-
as.character( spatialPolygonDataFrame$names(
spatialPolygonDataFrame at data[i]))

}

Subsetting on a variable should work just fine. I don't see any need for
paste().

Sarah
-- 
Sarah Goslee


http://www.functionaldiversity.org



More information about the R-help mailing list