【发布时间】:2014-01-02 02:18:33
【问题描述】:
如何制作一个 text-section-dataframes 列表editstart(对于给定的文本)editend,其中该部分的每个句子都有一个特定的 ID? (与下面的简单示例不同,句子的数量并不总是相同。)
sent <- character()
id <- character()
section <- data.frame(SentIDs=character(), Sentences=character(), stringsAsFactors=FALSE)
textList <- list(section)
sections <- 3
sentences <- 5
for(i in 1:sections){
for (j in 1:sentences){
textList[[i]][j,1] <- paste(i, j, sep=",") # ID of one sentence is put into the section dataframe inside the textList
textList[[i]][j,2] <- paste("sent", j, sep=" ") # sentence is put into the section dataframe inside the textList
}
}
textList
返回错误和错误输出
Error in `*tmp*`[[i]] : subscript out of bounds
> textList
[[1]]
SentIDs Sentences
1 1,1 sent 1
2 1,2 sent 2
3 1,3 sent 3
4 1,4 sent 4
5 1,5 sent 5
需要的输出
> textList
[[1]]
SentIDs Sentences
1 1,1 sent 1
2 1,2 sent 2
3 1,3 sent 3
4 1,4 sent 4
5 1,5 sent 5
[[2]]
SentIDs Sentences
1 2,1 sent 1
2 2,2 sent 2
3 2,3 sent 3
4 2,4 sent 4
5 2,5 sent 5
[[3]]
SentIDs Sentences
1 3,1 sent 1
2 3,2 sent 2
3 3,3 sent 3
4 3,4 sent 4
5 3,5 sent 5
谢谢! :)
【问题讨论】: