Re: [R] Creating a variable which is the sum of equal rows in a dataframe

2009-05-04 Thread Gabor Grothendieck
Try aggregate. First we read the data into DF and then apply aggregate: > Lines <- "Firm Banks + 500600700 Citybank + 500600700 CGD + 500600700 BES + 500600800 Citybank + 500600800 Bank1 + 500600900 CGD" > # DF <- read.table

Re: [R] Creating a variable which is the sum of equal rows in a dataframe

2009-05-04 Thread Fredrik Karlsson
Hi Cecilia, You can use table for this: #Generate a dataframe > dat.df <- data.frame(Firm = > sample(c(500600700,500600800,500600800),6,replace=TRUE),Banks=sample(c("Citybank","CGD","DES","Bank1"),6,replace=TRUE) > ) #Get the counts in a table format > with(dat.df, table(Firm,Banks))

Re: [R] Creating a variable which is the sum of equal rows in a dataframe

2009-05-04 Thread baptiste auguie
Try this, # d <- read.table(pipe("pbpaste"), head=T) # read your data table(d) # library(reshape) cast(as.data.frame(table(d)), .~Firm, fun=sum) HTH, baptiste On 4 May 2009, at 13:19, Cecilia Carmo wrote: Hi everyone: I need to count the number of banks of each firm in my data. The firm

[R] Creating a variable which is the sum of equal rows in a dataframe

2009-05-04 Thread Cecilia Carmo
Hi everyone: I need to count the number of banks of each firm in my data. The firm is identified by the fiscal number. The banks of each firm appears like this: Firm Banks 500600700 Citybank 500600700 CGD 500600700 BES 500600800 Citybank