小编pot*_*kan的帖子

RStudio在Web浏览器中打开文档

当我在RStudio中输入帮助框的函数名称时,我会在Web浏览器中打开答案而不是RStudio-help窗口.?function例如,在输入时会发生同样的情况?which.这样做时我也在控制台中收到以下错误:

> ?which
Error in (function ()  : attempt to apply non-function
Error in (function ()  : attempt to apply non-function
Error in (function ()  : attempt to apply non-function
Run Code Online (Sandbox Code Playgroud)

这是在将R升级到版本3.1.3并且我在Ubuntu 14.04上之后发生的.

有谁知道如何解决这个问题 - 如何让RStudio在RStudio窗口中打开文档,而不是在Web浏览器中?

r rstudio

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

如何使用%>%运算符(dplyr)的逻辑函数

我不知道如何使用逻辑(例如which,any,all)功能与%>%操作者从dplyr在R.包我有值的矢量

aaa <- sample(1:5, 10, replace = TRUE)

我想知道它们中的哪一个是相同的4.当我尝试这个:

aaa == 4 %>% which(.)

我收到以下错误:

Error in which(.) : argument to 'which' is not logical

其他需要逻辑向量作为参数的函数也是如此,例如allany.

aaa == 4 %>% any

[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE

Warning message: In any(.) : coercing argument of type 'double' to logical

logic r which dplyr

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

如何在闪亮的数据表列中添加解释?

我在数据表的帮助下编写了一个闪亮的应用程序,我想制作一些小方块来解释每个列的含义.理想情况下,当您将光标移动到列的名称上时,我希望它们出现.

这是一个应用程序:

ui.R

library(shiny)

data(iris)

shinyUI(fluidPage(
  sidebarLayout(
    sidebarPanel(
      fluidRow(
        column(12,
               wellPanel(
                 radioButtons("species", label="Species:", 
                              choices=levels(iris$Species),
                              selected=levels(iris$Species)[1]

                 )
               )
        )
      )
    ),
    mainPanel(
      fluidRow(column(12,
                      dataTableOutput("table1")

      )
      )
    )
  )
)
)
Run Code Online (Sandbox Code Playgroud)

server.R

library(shiny)
library(dplyr)
library(tidyr)

data(iris)  


shinyServer(function(input, output) {

  iris1 <- reactive({
    iris %>% 
      filter(Species %in% input$species)
  })

  output$table1 <- renderDataTable({
    iris1()
  })
})
Run Code Online (Sandbox Code Playgroud)

当你将courser移到Species列名称上时,我想要像这样: 在此输入图像描述

它甚至可能吗?请帮忙.

r datatables shiny

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

Python socket.error:[Errno 104]由peer重置连接

我有一个代码,其中有13个客户端必须连接到服务器.然后服务器对客户端给出的数据进行一些计数.之后角色转变 - 服务器成为客户端,客户端成为接收数据的服务器.问题在于,当尝试进行第一次连接时,即13个客户端尝试连接到服务器时,我不断收到此错误: [Errno 104] Connection reset by peer.我尝试了一些解决方法,例如尝试在第二个间隔中连接5次但没有任何效果.

这是我的代码:

server.py

import socket, pickle, numpy as np
import struct
import math


while 1:
    HOST = ''
    PORT = 50007
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((HOST, PORT))
    s.listen(13)

adresses = []
ports = []

i = 0
print("receiving...")
while i < 13:
    i += 1    
    #wait to accept a connection - blocking call
    conn, addr = s.accept()
    print ('Connected with ', addr)
    adresses.append(addr[0])
    buf = b''
    while len(buf) < 4:
        buf …
Run Code Online (Sandbox Code Playgroud)

python sockets

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

使用 cv.glmnet 并行设置种子在 R 中给出不同的结果

我在 1000 多个数据集上cv.glmnetglmnet包中并行运行。在每次运行中,我都会设置种子以使结果可重现。我注意到的是我的结果不同。问题是当我在同一天运行代码时,结果是一样的。但第二天他们就不同了。

这是我的代码:

model <- function(path, file, wyniki, faktor = 0.75) {

  set.seed(2)

  dane <- read.csv(file)

  n <- nrow(dane)
  podzial <- 1:floor(faktor*n)


  ########## GLMNET ############
  nFolds <- 3

  train_sparse <- dane[podzial,]
  test_sparse  <- dane[-podzial,]

  # fit with cross-validation
  tryCatch({
    wart <- c(rep(0,6), "nie")
    model <- cv.glmnet(train_sparse[,-1], train_sparse[,1], nfolds=nFolds, standardize=FALSE)

    pred <- predict(model, test_sparse[,-1], type = "response",s=model$lambda.min)

    # fetch of AUC value
    aucp1 <- roc(test_sparse[,1],pred)$auc

  }, error = function(e) print("error"))

  results <- data.frame(auc = aucp1, n …
Run Code Online (Sandbox Code Playgroud)

parallel-processing r glmnet random-seed

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

更新到R 3.4后,RStudio没有看到包

我有Ubuntu 16.04,在更新R到3.4.1版之后,即使它们也已更新,它也看不到我的包:

> library(dplyr)
Error in library(dplyr) : there is no package called ‘dplyr’
Run Code Online (Sandbox Code Playgroud)

包裹在那里:

$ ls ~/R/x86_64-pc-linux-gnu-library/3.4/ | grep plyr
dplyr
plyr
Run Code Online (Sandbox Code Playgroud)

我的.libPaths:

> .libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"       "/usr/lib/R/library" 
Run Code Online (Sandbox Code Playgroud)

设置.libPaths到所需的路径只会为一个会话.我希望它是永久性的.

我也尝试设置变量R_LIBS,R_LIBS_SITE并设置R_LIBS_USER此处所示的所需路径,但它仅在控制台中起作用(在RStudio中不起作用).

r path

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

使用 R 中的标记向分组箱形图添加抖动

我希望交互式(这意味着可以通过框/套索选择来选择它们)抖动点显示在分组箱线图上。我提出了这个问题:Add jitter to boxplot usingmarkers inplotly。我想要完全相同,但箱线图应该分组。

我做了一个箱线图,但要点都混淆了:

dat %>%
  plot_ly(x = ~as.numeric(IC), 
            y = ~xval, 
            color = ~gene, 
            type = "box",
            hoverinfo = "none",
            boxpoints = FALSE
          ) %>%
  add_markers(x = ~jitter(as.numeric(IC)),
              y = ~xval,
              color = ~gene,
              marker = list(size = 3),
              hoverinfo = "text",
              text = txt,
              showlegend = TRUE) %>%
layout(boxmode = "group")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

当我尝试按因子对 X 轴进行分组(以便每个组合都是一个级别)时,我无法对箱线图进行分组:

dat <- dat %>% 
  mutate(gene_x_covariate = as.factor(
    paste0(get(facet_title), "-", gene))) 

dat %>%
  plot_ly(x …
Run Code Online (Sandbox Code Playgroud)

r boxplot plotly jitter

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

Plotly,在add_markers创建的点周围添加边框

我正在尝试创建一个plotly带点边界的散点图.

理想的是:

plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length,
        marker = list(size = 10,
                       color = 'rgba(255, 182, 193, .9)',
                       line = list(color = 'rgba(152, 0, 0, .8)',
                                   width = 2)))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

但在我(更复杂)的情况下,我正在用这样的add_markers函数创建情节:

plot_ly(data = iris) %>% 
             add_markers(x = ~Sepal.Length, y = ~Petal.Length,
                           color = 'rgba(255, 182, 193, .9)')
Run Code Online (Sandbox Code Playgroud)

有了这个,line参数给出了线而不是点周围的边界: 在此输入图像描述

添加symbol = "circle-open"为参数也无济于事.

请帮忙.

r border scatter-plot r-plotly

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