[R] factor as seq() in for loop
Tord Snall
Tord.Snall at helsinki.fi
Mon Sep 19 19:34:54 CEST 2005
Dear all,
I would like to use the values in vegaggr.BLMCMR02$colony
str(vegaggr.BLMCMR02)
`data.frame': 1678 obs. of 3 variables:
$ vegtype : Factor w/ 27 levels "2010","2020",..: 3 4 5 19 4 5 19 5
$ colony : Factor w/ 406 levels "0","1","10","100",..: 1 1 1 1 2 2 2
$ Totvegproparea: num 0.00055 0.03956 0.95705 0.00284 0.05215 ...
as the seq in a for loop (for(var in seq)), and therefore first picked them
out as
cols = aggregate(list(A = vegaggr.BLMCMR02$Totvegproparea),
list(colony = vegaggr.BLMCMR02$colony), sum)[,1]
> str(cols)
Factor w/ 406 levels "0","1","10","100",..: 1 2 3 4 5 6 7 8 9 10 ...
I next planned to transform cols using as.integer(cols). However, this
transformation gives a vector corresponding to seq(from=1,to=length(cols)).
Could someone please give advice on how to make use of a factor as the seq
in a for loop (which is strictly not allowed' according to ?Control).
Thanks!
Tord
More information about the R-help
mailing list