【860】R programming related knowledge
Ref: R 字符串
Ref: R语言遍历文件和批量输出文件
setwd(dir)getwd()getwd returns an absolute filepath representing the current working directory of the R process; setwd(dir) is used to set the working directory to dir.
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.
paste(..., sep = " ", collapse = NULL, recycle0 = FALSE)Concatenate vectors after converting to character.
paste0(..., collapse = NULL, recycle0 = FALSE)The sepis set with nothing by default.
ls()Return a vector of variables. rm()Remove the specific variable.
c()It is used to create a list to a vector.
append(x, values, after = length(x))Add elements to a vector. The value will not add to xdirectly.
> a = list()
> for (i in c(1:10)) {a = append(a, i)}
grep, grepl, regexpr, gregexpr, regexec and gregexec search for matches to argument pattern within each element of a character vector: they differ in the format of and amount of detail in the results.
list.files(path = ".", pattern = NULL, all.files = FALSE,It produces a character vector of the names of files or directories in the named directory.
full.names = FALSE, recursive = FALSE,
ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
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' )
}
浙公网安备 33010602011771号