Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何在';块';一排_R - Fatal编程技术网

R 如何在';块';一排

R 如何在';块';一排,r,R,我有一个叫做textPrep的函数。这将获取一列文本,并根据文本中的标题以及其他内容对其进行细分。该函数无法真正处理超过2000行的数据,否则会减慢速度并悄然崩溃 目前我没有时间重新设计功能,但我确实需要它。所以我有50000行,我必须做一些类似的事情: output1<-EndoMineR::textPrep(MyText[1:1000,]$new,mydelimEndo) output2<-EndoMineR::textPrep(MyText[1001:2000,]$new,my

我有一个叫做textPrep的函数。这将获取一列文本,并根据文本中的标题以及其他内容对其进行细分。该函数无法真正处理超过2000行的数据,否则会减慢速度并悄然崩溃

目前我没有时间重新设计功能,但我确实需要它。所以我有50000行,我必须做一些类似的事情:

output1<-EndoMineR::textPrep(MyText[1:1000,]$new,mydelimEndo)
output2<-EndoMineR::textPrep(MyText[1001:2000,]$new,mydelimEndo)
output3<-EndoMineR::textPrep(MyText[2001:3000,]$new,mydelimEndo)
output4<-EndoMineR::textPrep(MyText[3001:4000,]$new,mydelimEndo)

#etc.    

output1_2<-rbind(output1,output2)
output3_4<-rbind(output3,output4)
oot<-rbind(output1_2,output3_4)

#etc.

output1这里有一种方法可以将数据分成多个组,然后对每个组调用函数(由您选择的长度索引定义)

#生成数据
n=1e5+300
N

df编写一个函数,并通过
m调用它(m
将其应用于输出*?为了避免问一个简单的问题,我如何在FUN=sum中运行参数化函数?在我尝试FUN=textPrep,inputText=mydelimEndo的那一刻)其中,mydelimEndo是单词向量,inputText是函数定义的参数名称。try
res[[i]]
# generate data
n = 1e5 + 300
n
df <- data.frame(a = rnorm(n), b = rnorm(n))

# define groups for function
breaks <- seq(0, nrow(df), by = 1000)
if(tail(breaks,1) < nrow(df)) breaks <- c(breaks,Inf)
group <- cut(x = seq(nrow(df)), breaks, include.lowest = TRUE)

# set up list for results of each group
res <- vector("list", length = length(levels(group)))

# fill in list by call to function on each group
for(i in seq(res)){
  mat <- which(match(as.character(group), levels(group)[i])==1)
  res[[i]] <- apply(df[mat,], 2, FUN = sum)
}

# results
res

# collapse if desired
res2 <- do.call("rbind", res)
res2