【861】R programming related knowledge

发布时间 2023-07-18 15:23:09作者: McDelfino

Ref: R 字符串

Ref: R语言遍历文件和批量输出文件


head(x, n)Returns the first or last parts of a vector, matrix, table, data frame or function. Since head() and tail() are generic functions, they may also have been extended to other classes.

  This function is similar to df.head(n)in python.

nchar(x)It takes a character vector as an argument and returns a vector whose elements contain the sizes of the corresponding elements of x.

length(x)Get or set the length of vectors (including lists) and factors, and of any other R object for which a method has been defined.

  This function is similar to len(x)in python.

toupper()/tolower()

substring(x, start, stop)Extract or replace substrings in a character vector.

 

list.files(path = ".", pattern = NULL, all.files = FALSE,
           full.names = FALSE, recursive = FALSE,
           ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
It produces a character vector of the names of files or directories in the named directory.

list.dirs()

If wanting to batch files, forloop can be used as follows,

for (i in 1:length(files)) {
    file = read.table(files[i], sep='\t')   
}
for (i in 1:length(files)) {
    file = read.table(files[i], sep='\t')   
}