小编jac*_*ger的帖子

使用tm_map(...,tolower)将文本转换为小写时出错

我试过用了tm_map.它给出了以下错误.我怎么能绕过这个?

 require(tm)
 byword<-tm_map(byword, tolower)

Error in UseMethod("tm_map", x) : 
  no applicable method for 'tm_map' applied to an object of class "character"
Run Code Online (Sandbox Code Playgroud)

r lowercase tm term-document-matrix

48
推荐指数
2
解决办法
6万
查看次数

诊断R包构建错误:pdfLatex不可用

我正在尝试构建一个包R.我制作了骨架,并运行了命令R CMD check package1.我在这里描述了一个错误.我按照解决方案步骤,结果是:

  1. devtools不适用R 2.15.1

  2. 拳打脚踢R CMD Rd2pdf package1.

Hmm.. Looks like a package
Converting Rd files to LaTeX
Creating pdf output from LaTeX
Error in texi2dvi(file=file, pdf=true, clean=clean, quiet=quiet, : pdflatex not available
Error in running tools::texi2pdf
Run Code Online (Sandbox Code Playgroud)
  1. 我抬头一看除其他事项外,安装了完整的TEX Live&MIKTEX.出现相同的错误消息.
  2. 我导航到pdflatex所在的目录,并尝试从那里运行命令.没有帮助.

我在这里缺少什么,或者有解决方法吗?或许,有没有办法在包创建过程中抑制pdf生成?

更新:当我在LINUX(CentOS)中尝试它时,没有抛出此错误.

packaging r pdflatex

13
推荐指数
3
解决办法
9157
查看次数

使用正则表达式在R中提取特定长度的单词

我有一个代码(我在这里得到):

m<- c("Hello! #London is gr8. I really likewhatishappening here! The alcomb of Mount Everest is excellent! the aforementioned place is amazing! #Wow")

x<- gsub("\\<[a-z]\\{4,10\\}\\>","",m)
x
Run Code Online (Sandbox Code Playgroud)

我试过其他方法,比如

m<- c("Hello! #London is gr8. I really likewhatishappening here! The alcomb of Mount Everest is excellent! the aforementioned place is amazing! #Wow")

x<- gsub("[^(\\b.{4,10}\\b)]","",m)
x
Run Code Online (Sandbox Code Playgroud)

我需要删除长度小于4或大于10的单词.我哪里错了?

regex string r

10
推荐指数
1
解决办法
4952
查看次数

将元素添加到R中的列表(在嵌套列表中)

我有一个嵌套列表l3:

l1<- as.list(c(1,2,3,4,5))
l1

l2<- as.list(c(6,7,8,9,10))
l2

l3<- list(l1,l2)
l3
Run Code Online (Sandbox Code Playgroud)

l3显示为:

> l3
[[1]]
[[1]][[1]]
[1] 1

[[1]][[2]]
[1] 2

[[1]][[3]]
[1] 3

[[1]][[4]]
[1] 4

[[1]][[5]]
[1] 5


[[2]]
[[2]][[1]]
[1] 6

[[2]][[2]]
[1] 7

[[2]][[3]]
[1] 8

[[2]][[4]]
[1] 9

[[2]][[5]]
[1] 10
Run Code Online (Sandbox Code Playgroud)

我需要添加第三个列表l4到l3,这样l3变成:

[[1]][[1]]
    [1] 1

to

[[2]][[5]]
    [1] 10


[[3]][[1]]
    [1] 30

[[3]][[2]]
    [1] 32

[[3]][[3]]
    [1] 33

[[3]][[4]]
    [1] 34

[[3]][[5]]
    [1] 35
Run Code Online (Sandbox Code Playgroud)

其中l4是:

l4<- as.list(c(31,32,33,34,35))
Run Code Online (Sandbox Code Playgroud)

我该如何完成它?我已经尝试过(c),list甚至明确地提出了论点并得到了一个out of bounds error …

r list

6
推荐指数
2
解决办法
4万
查看次数

如何从R中的推文中提取主题标签?

我知道这个问题已在这里这里被问到,但是当我尝试它时出现了一个小问题:

x<- str_extract("Hello peopllz! My new home is #crazy gr8! #wow", "#\S+")
Error: '\S' is an unrecognized escape in character string starting "#\S"
Run Code Online (Sandbox Code Playgroud)

我改变了正则表达式"#(.+) ?","#\\s"但他们并没有提取井号标签.

然后我尝试了gsub方式:

x<- gsub("[^#(.+) ?]","","Hello! #London is gr8. #Wow")
Run Code Online (Sandbox Code Playgroud)

它给了: " # . #"

我出错的任何想法?我希望我的输出作为推文中所有主题标签的向量/列表(没有哈希!)

编辑:我不希望对推文进行标记,因为:1.我没有为我的程序的其余部分标记推文,2.如果我扩展它以处理大量的推文,那将是一个非常昂贵的步骤.

regex r tweets

5
推荐指数
1
解决办法
5808
查看次数

R CMD检查错误:需要包但不可用

我正在尝试创建一个包.这取决于几个包.我将导入添加到命名空间文件中,并将Depends添加到描述文件中.

我在这里这里找到了可能的解决方案,但这些都没有用 - 我想因为我在CentOS上.

这就是我在屏幕上看到的内容:

[hadoop@localhost RProjects]$ sudo R CMD check TextPreProcess
* using log directory ‘/home/hadoop/RProjects/TextPreProcess.Rcheck’
* using R version 2.15.1 (2012-06-22)
* using platform: x86_64-redhat-linux-gnu (64-bit)
* using session charset: UTF-8
* checking for file ‘TextPreProcess/DESCRIPTION’ ... OK
* checking extension type ... Package
* this is package ‘TextPreProcess’ version ‘1.0’
* checking package namespace information ... OK
* checking package dependencies ... ERROR
Packages required but not available:
  ‘RWeka’ ‘Snowball’ ‘lsa’ ‘plyr’ ‘snowfall’ …
Run Code Online (Sandbox Code Playgroud)

packaging r

5
推荐指数
1
解决办法
2949
查看次数

"未在此范围内声明的函数"编译openCV代码时出错

我正在尝试编写一些使用openCV函数的代码.我首先介绍了文档中提供的一些示例代码:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
    if( argc != 2)
    {
     cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
     return -1;
    }

    Mat image;
    image = imread(argv[1]);   // Read the file

    if(! image.data )                              // Check for invalid input
    {
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }

    namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
    imshow( …
Run Code Online (Sandbox Code Playgroud)

c++ opencv image-processing

4
推荐指数
1
解决办法
2万
查看次数

基于成对相等性对列进行分组

我有一个名为equalityMatrix的矩阵

> equalityMatrix
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16] [,17] [,18]
[1,]   29   29   29   29   55   55   55   55  101   101   101   111   111   115   134   134   134   151
[2,]  101  111  115  316  134  151  235  319  111   115   316   115   316   316   151   235   319   235
     [,19] [,20]
[1,]   151   235
[2,]   319   319
Run Code Online (Sandbox Code Playgroud)

(做你的:)

structure(c(29L, 101L, 29L, 111L, 29L, 115L, 29L, 316L, 55L, 
134L, 55L, 151L, …
Run Code Online (Sandbox Code Playgroud)

combinations r

3
推荐指数
1
解决办法
74
查看次数

如何增加 Tez 的容器物理内存?

我一直在aws emr 4.8使用 hive 1.0 和 tez 0.8的集群上运行一些 hive 脚本。

我的配置如下所示:

SET hive.exec.compress.output=true;
SET mapred.output.compression.type=BLOCK;
SET hive.exec.dynamic.partition = true;
SET hive.exec.dynamic.partition.mode = nonstrict;
set hive.execution.engine=tez;
set hive.merge.mapfiles=false;
SET hive.default.fileformat=Orc;
set tez.task.resource.memory.mb=5000;
SET hive.tez.container.size=6656;
SET hive.tez.java.opts=-Xmx5120m;
set hive.optimize.ppd=true;
Run Code Online (Sandbox Code Playgroud)

我的全局配置是:

hadoop-env.export   HADOOP_HEAPSIZE 4750
hadoop-env.export   HADOOP_DATANODE_HEAPSIZE    4750
hive-env.export HADOOP_HEAPSIZE 4750
Run Code Online (Sandbox Code Playgroud)

在运行我的脚本时,我收到以下错误:

Container [pid=19027,containerID=container_1477393351192_0007_02_000001] is running beyond physical memory limits. Current usage: 1.0 GB of 1 GB physical memory used; 1.9 GB of 5 GB virtual memory used. Killing container.
Run Code Online (Sandbox Code Playgroud)

在谷歌搜索这个错误时,我读到 set …

hadoop hive amazon-emr apache-tez tez

3
推荐指数
2
解决办法
2万
查看次数

使用outer()替换R中的嵌套for

我有一个简单的R代码来添加2​​x2矩阵的组件

sum<-0
for(i in 1:2){ # row
    for(j in 1:2){ #column
      sum<-sum+mat[i,j]
    }
  }
Run Code Online (Sandbox Code Playgroud)

是否可以使用outer()或任何其他函数来替换这段代码并使其更有效?我的目标是在我的整个代码中替换嵌套的for循环,以减少执行程序所需的时间.

编辑:我也想尝试在代码片段上使用它,如:

for(i in 1:2){ # row
    for(j in 1:2){ #coloumn

      chisqr<- chisqr+ ((mat[i,j]-expmat[i,j])^2)/expmat[i,j]

    }
  }
Run Code Online (Sandbox Code Playgroud)

和:

  for(i in 1:2){ # row
    for(j in 1:2){ #coloumn
      rowsum<-0
      colsum<-0

      for(k in 1:2){
        rowsum<- rowsum+mat[i,k]
      }

      for(k in 1:2){
        colsum<- colsum+mat[k,j]
      }

      expmat[i,j]<- (rowsum*colsum)/sum
    }
  }
Run Code Online (Sandbox Code Playgroud)

r outer-join

1
推荐指数
1
解决办法
150
查看次数

在R中调试 - 如何找到错误?

我正在尝试编写一个函数,当一个文本进行搬运工堵塞时,该函数返回单词的词干映射.当我试图运行一个例子时,代码不会停止运行,即没有输出.没有错误,但当我强制停止它时,它会发出警告:

1: In stemList[length(stemList) + 1][2] <- flatText[i] :
  number of items to replace is not a multiple of replacement length
2: In stemList[length(stemList) + 1][2] <- flatText[i] :
  number of items to replace is not a multiple of replacement length
3: In stemList[length(stemList) + 1][2] <- flatText[i] :
  number of items to replace is not a multiple of replacement length
4: In stemList[length(stemList) + 1][2] <- flatText[i] :
  number of items to replace is not a multiple of replacement …
Run Code Online (Sandbox Code Playgroud)

debugging r porter-stemmer

0
推荐指数
1
解决办法
145
查看次数