小编Tin*_*esh的帖子

如何计算mongodb集合中的文档数量

我想知道如何计算集合中的文档数量.我尝试了以下

var value = collection.count();
&&
var value = collection.find().count()
&&
var value = collection.find().dataSize()
Run Code Online (Sandbox Code Playgroud)

我总是得到方法未定义.

你能告诉我用什么方法来查找收集中的总文件.

谢谢Ganesh

mongodb

17
推荐指数
4
解决办法
5万
查看次数

如何在MongoDB的查询中使用正则表达式变量

我想基于我构造的正则表达式查询MongoDB文档.例如,我构建了一个简单的正则表达式,如下所示,它是Nodejs中随机字母和随机数的组合

var randnum = Math.floor((Math.random() * 10) + 1);
var alpha = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','X','Y','Z'];
var randletter = alpha[Math.floor(Math.random() * alpha.length)];
var val = randletter + randnum + '.*;
Run Code Online (Sandbox Code Playgroud)

我已尝试过各种正则表达式变量的组合

var stream = collection.find({"FirstName": /val/).stream();
&&
var stream = collection.find({"FirstName": /$val/).stream();
&&
var stream = collection.find({"FirstName": {$in : [{$regex:val}]}}).stream()
&&
var stream = collection.find({"FirstName": {$in : [{$regex:$val}]}}).stream()
Run Code Online (Sandbox Code Playgroud)

没有它似乎工作.但是当我写实际的正则表达式时,我得到了例如的记录

var stream = collection.find({"FirstName": /J.*/).stream();
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

谢谢Ganesh

mongodb node.js

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

isChecked()行为与2.3.6和4.2安卓版本完全相反

我正在开发一个简单的Android应用程序,它创建一个带有复选框的ListView,如下所示

listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice,results);
this.setListAdapter(listAdapter);
ListView lv = getListView();
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

lv.setOnItemClickListener(new OnItemClickListener(){
    @Override
     public void onItemClick(AdapterView<?> parent, View view, int position,
                        long id) {
           CheckedTextView check = (CheckedTextView)view;
           //The below code needed for running on AVD version 4.2
           if(check.isChecked()) { 
                   // Checkbox checked do something 
            } 
           else { 
                    // Not checked. Do something 
            }
            /* Exact opposite need on Samsung phone running 2.3.6
            if(!check.isChecked()) {
                      // Checkbox checked do something
            }
            else {
             // Not checked. DO something …
Run Code Online (Sandbox Code Playgroud)

android android-checkbox

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

如何在ggplot的aes_string中调用reorder

我需要使用ggplot和aes_string()将条形图从高到低(从左到右)重新排序.例如,对于数据帧df < - f(X,Y,Z),可以使用

 ggplot(top10,aes(x=reorder(X,-Y),y=Y,fill=X) + geom_bar(stat="identity")
Run Code Online (Sandbox Code Playgroud)

但我需要通过引用数据帧的列号而不是列名来实现这一点,如下所示

 ggplot(top10, aes_string(x=colnames(top10)[num1],y=meanFeat, 
 fill=colnames(top10)[num1])) +  geom_bar(stat="identity")
Run Code Online (Sandbox Code Playgroud)

上面的语句使用列号绘制输出.但它不会从高到低重新排序(从左到右)

如何在aes_string中使用重新排序功能来实现这一目标?

r ggplot2

8
推荐指数
2
解决办法
1311
查看次数

sklearn-LinearRegression:无法将字符串转换为浮点型:'-'

我正在尝试使用来自sklearn的LinearRegression,并且收到“无法将字符串转换为浮点型”的信息。数据框的所有列都是浮点型的,输出y也是浮点型的。我看过其他帖子,建议将其转换为浮动内容。

<class 'pandas.core.frame.DataFrame'>
Int64Index: 789 entries, 158 to 684
Data columns (total 8 columns):
f1     789 non-null float64
f2     789 non-null float64
f3     789 non-null float64
f4     789 non-null float64
f5     789 non-null float64
f6     789 non-null float64
OFF    789 non-null uint8
ON     789 non-null uint8
dtypes: float64(6), uint8(2)
memory usage: 44.7 KB

type(y_train)
pandas.core.series.Series
type(y_train[0])
float

from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(X,Y,random_state=0)
X_train.head()
from sklearn.linear_model import LinearRegression
linreg = LinearRegression().fit(X_train, y_train)
Run Code Online (Sandbox Code Playgroud)

我得到的错误是

ValueError                                Traceback (most recent call last)
<ipython-input-282-c019320f8214> in …
Run Code Online (Sandbox Code Playgroud)

python pandas scikit-learn valueerror

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

撤消R中的布局

我最初创建的图是boxplot和histogram的组合.为此我设置

nf <- layout(mat = matrix(c(1,2),2,1, byrow=TRUE),  height = c(1,3))
par(mar=c(2,2,1,1))
# Draw box plot
# Draw histogram
Run Code Online (Sandbox Code Playgroud)

在此之后,我需要创建一个常规的情节.但我发现所有后续的图都试图遵循相同的布局.一个在顶部,另一个在下面.

如何将布局重置为默认值?

我应该使用nf < - layout(mat = matrix(c(1,1),1,1,byrow = FALSE))

谢谢Ganesh

layout r reset

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

如何在Shiny中使用自己的一组小部件创建多个页面

我希望能够创建多个页面,每个页面都有一组小部件下拉,单选按钮和绘制地图的空间.Shiny教程展示了如何创建多个页面

shinyUI(navbarPage("My Application",
  tabPanel("Component 1"),
  tabPanel("Component 2"),
  tabPanel("Component 3")
))
Run Code Online (Sandbox Code Playgroud)

如何在每个页面中添加小部件,例如如何将以下内容添加到组件1?

  sidebarLayout(
    sidebarPanel(
        selectizeInput(
            'id', label = "Year", choices =   NULL,multiple=FALSE,selected="X2015",
            options = list(create = TRUE,placeholder = 'Choose the year')

        ),
        # Make a list of checkboxes
        radioButtons("radio", label = h3("Radio buttons"),
                     choices = list("Choice 1" = 1,
                                   "Choice 2" = 2)
Run Code Online (Sandbox Code Playgroud)

     mainPanel(
        plotOutput("distPlot")
    )
Run Code Online (Sandbox Code Playgroud)

r shiny

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

我们可以在同一个面板中使用 Shiny 进行打印或绘图吗?

我想打电话

 output$IPLMatchPlot <- renderPlot({ 

 f(x)
Run Code Online (Sandbox Code Playgroud)

}) 或者

 output$IPLMatchPrint <- renderPrint({
   f(x)
 })
Run Code Online (Sandbox Code Playgroud)

函数 f(x) 返回绘图或数据框。

我可以在 server.R 中单独执行此操作,但希望显示为数据框的绘图或文本。有关如何执行此操作的任何建议

r shiny

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

Shiny:数据框只显示 10 行

我有一个 Shiny 应用程序,它可以显示绘图或打印数据框。虽然它两者都做,但它只打印数据框的第 10 行并添加“... 86 行”。我想显示至少 40 行数据框。我尝试了 a & head(a, n=50) 但它只显示总数的 10 行。我怎样才能让它显示更多的行。

这就是我所拥有的

服务器

output$IPLMatch2TeamsPlot <- renderPlot({ 
    printOrPlotIPLMatch2Teams(input, output)

})

# Analyze and display IPL Match table
output$IPLMatch2TeamsPrint <- renderPrint({ 
    a <- printOrPlotIPLMatch2Teams(input, output)
    head(a,n=50)
    #a
})
output$plotOrPrintIPLMatch2teams <-  renderUI({ 
    # Check if output is a dataframe. If so, print
    if(is.data.frame(scorecard <- printOrPlotIPLMatch2Teams(input, output))){
        verbatimTextOutput("IPLMatch2TeamsPrint")
    }
    else{ #Else plot
        plotOutput("IPLMatch2TeamsPlot")
    }

})
Run Code Online (Sandbox Code Playgroud)

用户界面

   tabPanel("Head to head",
                        headerPanel('Head-to-head between 2 IPL teams'),
                        sidebarPanel(
                            selectInput('matches2TeamFunc', 'Select function', IPLMatches2TeamsFuncs), …
Run Code Online (Sandbox Code Playgroud)

r shiny

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

包tm:如何避免删除停用词

我想避免删除停用词,但我发现无论参数设置如何tm,总是删除一些停用词.

library(tm)
documents <- c("This is a list containing the tallest buildings in San    Francisco")
corpus <- Corpus(VectorSource(documents))
matrix <- DocumentTermMatrix(corpus,control=list(stopwords=FALSE))
colnames(matrix)
# [1] "buildings"  "containing" "francisco"  "list"       "san"       
# [6] "tallest"    "the"        "this"  
Run Code Online (Sandbox Code Playgroud)

DocumentTermMatrix 似乎删除了"是"和"在"中的停用词.

我怎么能避免这个?设置stopwords=TRUE仅阻止删除"the".我怎样才能防止删除"是"和"进入"?

r stop-words tm

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