If you use lapply you don't have to set up the storage area.
Here is an example. I have used textConnection with character
strings to make this reproducible but you can replace conn with
a vector of filenames,
# test data
Lines1 <- "
1 2
3 4
"
Lines2 <- "
11 12
13 14
"
conn <- list(textConnection(Lines1), textConnection(Lines2))
# this is code
f <- function(f) with(read.table(f), c(a = mean(V1), b = sd(V2)))
do.call(rbind, lapply(conn, f))
On 6/29/06, Cuau <cuauv at yahoo.com> wrote:>
> Hi everyone,
>
> I'm writting a script that will open multiple files in a single
folder and then will do some calculations to finally save everything in a big
table.
> So here is the pseudo code
>
> #read all files in the given directory
> myfiles <-list.files("c:\\myDir")
>
> #initialize table
> ???
>
> #loop through files
> for(f in myfiles[-1]) {
> netMat <- read.table( f, sep" " )
> netMat <-as.matrix(netMat)
>
> # calculate the needed Stats
> gden(netMat)->density
> centralization(netMat, degree) -> Gdegree
> centralization(netMat, betweenness) -> Gbetweenness
> centralization(netMat, closeness) -> Gcloseness
>
> #store into table
> ????
>
> }
>
> So my questions are two
>
> First how can I initialize the table (it will be a 4 X 1001 table)
without filling it out first.
> Second how can I store each value in the table (i.e. in each round
I'll be adding one full column with density and the 3 different
centralizations)?
>
> thks
>
> -Cuau
>
>
>
>
> ---------------------------------
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>