The following function is working with the dataset data21
charaFun <- function(col, data=data21) {
locus<-data[,col]
mean(locus, na.rm=T)
}
charaFun("TAPSE")
Now i want it to be applied to another datasets eg "data211","data212","data21m1","data21w2" which are subsets of data21 which specific conditions. How can i achieve this automatically?
You could place the datasets in a list
and use lapply
to process it all at once.
lst1 <- list(data211, data212, dat21m1, data21w2)
Or if the object names have a specific pattern
lst1 <- mget(ls(pattern="data\\d+"))
lapply(lst1, function(x) charaFun("TAPSE", data=x))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.