[R] howto get the number of columns and column names of multiply data frames

Frank Schäffer frank.schaeffer at kabelmail.de
Sun Aug 9 17:29:26 CEST 2009

I' ve read in several files with measurements into R data frames(works 
flawlessly). Each dataframe is named by the location of measurement and 
contains hundreds of rows and about 50 columns like this

date measurment_1  .... mesurement_n

For further processing I need to check whether or not ncol and colnames are 
the same for all dataframes. 
Also I need to add a new column to each dataframe with contain the name of the 
dataframe, so that this column can be treated as factor in later processing 
(after merging some seleted dataframes to one)

I tried out 

for (i in 1:length(ls()){

but this does not work because r returns a "character" for i and therefore 
"NULL" as result.
Reading the output of ls() into a list also does not work.

How can I accomplish this task??

Best regards and thanks


More information about the R-help mailing list