问使用lapply()-function求R中数据帧中每一行的均值ENWhile循环中read命令从标准输入中读取一行,并将内容保存到变量line中。在这里,-r选项保证读入的内容是原始的内容,意味着反斜杠转义的行为不会发生。输入重定向操作符< file打开并读取文件file,然后将它作为read命令的标准输入。
Apply(数据,运算函数,函数的参数,simplify = TRUE, USE.NAMES = TRUE) 对于其中的simplify参数,就是指明是否对返回的结果集重新组织,如果为FALSE,那么就相当于lapply了。USE.NAMES是对字符串数据处理时,是否使用字符串作为命名的。 还是上面的例子,只是把lapply换成sapply: sapply(s,function(x){if(is.numeric(x...
(chunks)) # object <- future_lapply( X = 1:nrow(x = chunks), #对 chunks 进行循环 FUN = function(i) { row <- chunks[i, ] #获取一行。数据框的本质也是 列list n1 <- as.numeric(x = row[[1]]) #第一列 n2 <- as.numeric(x = row[[2]]) #第二列 return( apply(df1[n1:n2...
"four", "five") # 创建一个字符串向量 > name(x) # 显示向量x的名字(其实就像是Excel中的表头) Error in name(x) : could not find function "name" > name(x) <- y # 将向量y作为向量x的名字 Error in name(x) <- y : could not find function "name<-" > names(x) # 显示向量x的名...
Apply a Function Over Valuesinan Environment 对环境中的值使用函数 eapply(env, FUN, ..., all.names= FALSE, USE.NAMES =TRUE) mapply Apply a Function to Multiple List or Vector Arguments 对多个列表或者向量参数使用函数 mapply(FUN, ..., MoreArgs= NULL, SIMPLIFY = TRUE, USE.NAMES =TRUE) ...
当您使用它将参数传递给另一个函数时,您必须仔细向用户解释这些参数的位置。 这使得很难理解你可以用lapply()和plot()这样的函数做什么. 拼写错误的参数不会引发错误。 这使得拼写错误很容易被忽视: sum(1, 2, NA, na_rm = TRUE) #> [1] NA 6.6.1 练习 ...
log.transform <-function(invec, multiplier =1) {## Function for the transformation, which is the log## of the input value times a multiplierwarningmessages <- c("ERROR: Non-numeric argument encountered in function log.transform","ERROR: Arguments to function log.transform must be greate th...
Lists and lapply function A list in R is a flexible data object that can be used to combine data of different types and different lengths for almost any purpose. Arbitrary lists can be created with either the list function or the c function; many other functions, especially the statistical ...
Many functions in R can be written as operators. An operator is a function that takes one or two arguments and can be written without parentheses. 加减乘除+取模等 用户自定二元运算符由一个包括在两个%%字符之间的字符串构成,如下 > `%myop%` <- function(a, b) {2*a + 2*b} ...
The update_key function allows the user to add or drop terms via the x (add a data.frame) and drop (drop a term) arguments. Below I drop the "a" and "h" terms (notice there are now 24 rows rather than 26): mykey_dropped <- update_key(mykey, drop = c("a", "h")) nrow...