Domanda

I have around 100 text files which I have loaded into R:

myFiles <- (Sys.glob("C:/../.../*.txt"))
dataFiles <- lapply(myFiles, read.table)

Files have different number of rows, but all have 4 columns. 1st column is the name and the last 3 are coordinates.

example of files:

[[1]]
         n         x        y        z
1       Bal   0.459405 -238.3565 -653.5304
2       tri   0.028990 -224.5127 -600.0000
.....
14      mon   24.514049 -264.7673 -627.0550

[[2]]
        n         x        y        z
1      bal 2.220795 -284.1022 -651.8112
2      reg 2.077444 -290.4326 -631.3667
...
8      tri  32.837284 -347.2596 -633.0000

There is one row which is present in all files: e.g. row.name="tri". I want to find summary (median,mean,max,min) of that row's coordinates (x,y,z) over all 100 files. I found quite a few examples of summary of a row in one file but not over multiple files. I think I need to use lapply but not sure how to start with it. Also I need summary to create classes later based on the values I have. I found "summary" function for taht to be sueful. If there is any other function which might be be of more use you could suggest for taht purposes it would be helpful. Any help would be great!

Thanks!

È stato utile?

Soluzione

For pulling all those "tri" rows together you can do:

df <- do.call("rbind", lapply(dataFiles, function(z) z[z$n=="tri",]))

summary(df)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top