[R] Column name assignment problem

Steve Murray smurray444 at hotmail.com
Mon Mar 30 14:22:05 CEST 2009

Dear all,

Apologies for yet another question (!). Hopefully it won't be too tricky to solve. I am attempting to add row and column names (these are in fact numbers) to each of the tables created by the code (120 in total).

# Create index of file names
files <- print(ls()[1:120], quote=FALSE)  # This is the best way I could manage to successfully attribute all the table names to a single list - I realise it's horrible coding (especially as it relies on the first 120 objects stored in the memory actually being the objects I want to use)...

  [1] "Fekete_198601" "Fekete_198602" "Fekete_198603" "Fekete_198604"
  [5] "Fekete_198605" "Fekete_198606" "Fekete_198607" "Fekete_198608"
  [9] "Fekete_198609" "Fekete_198610" "Fekete_198611" "Fekete_198612"
  [13] "Fekete_198701" "Fekete_198702" "Fekete_198703" "Fekete_198704"
  [17] "Fekete_198705" "Fekete_198706" "Fekete_198707" "Fekete_198708" ...[truncated - there are 120 in total]

# Provide column and row names according to lat/longs.

rnames <- sprintf("%.2f", seq(from = -89.75, to = 89.75, length = 360))
columnnames <- sprintf("%.2f", seq(from = -179.75, to = 179.75, length = 720))

for (i in files) {
        assign(colnames((paste(Fekete_",index$year[i], index$month[i])", sep='')), columnnames)
                assign(rownames(paste("rownames(Fekete_",index$year[i], index$month[i],")", sep=''), rnames))

Error: unexpected string constant in:
"for (i in files) {
assign(colnames((paste(Fekete_",index$year[i], index$month[i])""
>                 assign(rownames(paste("rownames(Fekete_",index$year[i], index$month[i],")", sep=''), rnames))
Error in if (do.NULL) NULL else if (nr> 0) paste(prefix, seq_len(nr),  : 
  argument is not interpretable as logical
In addition: Warning message:
In if (do.NULL) NULL else if (nr> 0) paste(prefix, seq_len(nr),  :
  the condition has length> 1 and only the first element will be used
>                     }
Error: unexpected '}' in "                    }"

Is there a more elegant way of creating a list of file names in this case (remember that there are 2 variable parts to each name) which would facilitate the assigning of column and row names to each table? (And make life easier when doing other things with the data, e.g. plotting...!).

Many thanks once again - the help offered really is appreciated.


All your Twitter and other social updates in one place 

More information about the R-help mailing list