Re: [R] initializing table and filling it out

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Fri 30 Jun 2006 - 01:54:51 EST

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@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@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
>



R-help@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 Received on Fri Jun 30 02:06:01 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 30 Jun 2006 - 04:12:57 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.