[STATSGRASS] Help - Inconsistent behavior, GRASS/R win/mac

Gregory Booma gcb2101 at columbia.edu
Wed May 11 11:43:28 EDT 2005


STATSGRASS list,

I've written an R script (see below) to create a new unique-id for
each row of a data.frame object. The script runs fine on .dbf and
.csv files created in ArcGIS 9.0 and Excel on Windows XP, but not
on those created in GRASS 6.0 and Excel on MacOSX 10.3.9. In GRASS,
I create the .dbf with v.in.ogr, and .csv with db.select output
piped to a file. When running the script (on Mac) on files created
on the Mac I get:

Error in "$<-.data.frame"(`*tmp*`, "newid", value = c(NA, NA, NA,
NA,  : replacement has 1059 rows, data has 1976

Using files created in Windows (and still running the script on Mac)
it runs without error.

My script is as follows:

# sort by unit-id and area (ascending, descending,
# respectively) and take frequencies of unit-id

df[order(POVID,-AREA),]
freqtable <- as.data.frame(table(df$POVID))

# code a unique id that is effectively a concatenation
# of the unit-id, sorted ascending, and its position in a sequence
# of duplicates (sequence = 1 if no duplicates), sorted descending
# by unit land area

for (i in 1:nrow(freqtable)){
	match <- which(df$POVID==freqtable$Var1[i])
	for (j in 1:length(match)){
		df$newid[match[j]] <- as.integer(df$POVID[match[j]]*10+j)
		}
    }

I've tinkered with different methods in R and tried saving files in
different ways - all to no avail. If anyone has a workaround for
this or can help me troubleshoot the problem I'd greatly appreciate
it.

Many thanks in advance,

Greg

--------------------------
Greg Booma
CIESIN - Columbia U.
gcb2101 [at] columbia.edu





More information about the grass-stats mailing list