我在R中有一个包含大量单词的字符串.查看字符串时,我收到大量文本,其中包含类似于以下内容的文本:
>docs
....
\u009cYes yes for ever for ever the boys cried in their ringing voices with softened faces
....
Run Code Online (Sandbox Code Playgroud)
所以我想知道如何从字符串中删除这些\ u009字符(所有字符,其中一些字符略有不同).我尝试过使用gsub(),但是从字符串中删除内容效果不佳.
我正在尝试将网页源读入R并将其作为字符串处理.我试图删除段落并从段落文本中删除html标签.我遇到了以下问题:
我尝试实现一个删除html标签的函数:
cleanFun=function(fullStr)
{
#find location of tags and citations
tagLoc=cbind(str_locate_all(fullStr,"<")[[1]][,2],str_locate_all(fullStr,">")[[1]][,1]);
#create storage for tag strings
tagStrings=list()
#extract and store tag strings
for(i in 1:dim(tagLoc)[1])
{
tagStrings[i]=substr(fullStr,tagLoc[i,1],tagLoc[i,2]);
}
#remove tag strings from paragraph
newStr=fullStr
for(i in 1:length(tagStrings))
{
newStr=str_replace_all(newStr,tagStrings[[i]][1],"")
}
return(newStr)
};
Run Code Online (Sandbox Code Playgroud)
这适用于某些标签,但不适用于所有标签,此失败的示例是跟随字符串:
test="junk junk<a href=\"/wiki/abstraction_(mathematics)\" title=\"abstraction (mathematics)\"> junk junk"
Run Code Online (Sandbox Code Playgroud)
目标是获得:
cleanFun(test)="junk junk junk junk"
Run Code Online (Sandbox Code Playgroud)
但是,这似乎不起作用.我认为它可能与字符串长度或转义字符有关,但我找不到涉及这些的解决方案.
如何在R中创建不同维度的矩阵向量.例如,我说我有两个矩阵
M1=array(0,dim=c(2,2))
M2=array(0,dim=c(3,3))
Run Code Online (Sandbox Code Playgroud)
然后我可以制作包含这些矩阵的向量C.
C[1]=M1
Run Code Online (Sandbox Code Playgroud)
和
C[2]=M2.
Run Code Online (Sandbox Code Playgroud)
我知道我可以创建一个三维数组
C=array(NA,dim=c(2,3,3)
Run Code Online (Sandbox Code Playgroud)
但我知道如何做到这一点的唯一方法就是拥有
C[1,,]
Run Code Online (Sandbox Code Playgroud)
数组中的元素有必要的空间.