我有一个向量列表,说:
li <- list( c(1, 2, 3),
c(1, 2, 3, 4),
c(2, 3, 4),
c(5, 6, 7, 8, 9, 10, 11, 12),
numeric(0),
c(5, 6, 7, 8, 9, 10, 11, 12, 13)
)
Run Code Online (Sandbox Code Playgroud)
我想删除已经包含在其他(更大或相等)的所有向量,以及所有空向量
在这种情况下,我只剩下列表
1 2 3 4
5 6 7 8 9 10 11 12 13
Run Code Online (Sandbox Code Playgroud)
实现这一目标是否有任何有用的功能?
提前致谢
我有一个如下所示的数据集:
structure(list(A = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24",
"25"), class = "factor"), T = c(0.04, 0.08, 0.12, 0.16, 0.2,
0.24), X = c(464.4, 464.4, 464.4, 464.4, 464.4, 464.4), Y = c(418.5,
418.5, 418.5, 418.5, 418.5, 418.5), V = c(0, 0, 0, 0, 0, 0),
GD = c(0, 0, 0, 0, 0, 0), ND …
Run Code Online (Sandbox Code Playgroud) I have about 10000 replicates of a sample in a matrix. My matrix has 1000 rows and 6 columns. Numbers in the columns range from 0:58 depending on the sample.
actual.prob <- c(.14, .14, .16, .13, .19, .24)
million.rep <- replicate(10000, sample(1:6, 58, replace= T, actual.prob))
new.matrix <- matrix(nrow= 10000, ncol=6)
for(i in 1:10000){
new.matrix[i,] <- as.vector(table(factor(million.rep[,i], levels=1:6)))
}
new.matrix[1:10,]
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 3 7 11 11 11 15
[2,] 7 6 12 5 19 9 …
Run Code Online (Sandbox Code Playgroud) 当两个条件True
在矩阵中时,选择元素的方法是什么?在R中,基本上可以组合布尔的向量.
所以我的目标是:
A = np.array([2,2,2,2,2])
A < 3 and A > 1 # A < 3 & A > 1 does not work either
Run Code Online (Sandbox Code Playgroud)
Evals to:ValueError:具有多个元素的数组的真值是不明确的.使用a.any()或a.all()
它应该评估为:
array([True,True,True,True,True])
Run Code Online (Sandbox Code Playgroud)
我的解决方法通常是将这些布尔向量相加并等于2,但必须有更好的方法.它是什么?
我有一个闪亮的 R 应用程序,其中使用“renderTable”函数来渲染动态创建的表。该表在一种情况下可以具有 3 个字符列和 4 个数字列,在另一种情况下可以具有 2 个字符列和 2 个数字列。ui.R 的 renderTable 代码是:
output$table1 <- renderTable({
d1<-data()
print(format(d1, big.mark=",", scientific=FALSE,justify="right", nsmall=0))
})
Run Code Online (Sandbox Code Playgroud)
这适用于除 justify 之外指定的所有格式选项。所有数字列在输出中均左对齐。
谁能解释一下为什么?
如何查看Ubuntu系统上安装的闪亮服务器的版本?
背景:在Ubuntu14 32位虚拟机上安装了shiny-server(即从源代码构建).它已启动并运行,但尚未运行良好,并且为了搜索我的问题的解决方案,我需要知道闪亮的服务器版本.
# returns the expression supplied to the first argument
get_expr <- function(x) as.expression(substitute(x))
identical(expression(a + 1), get_expr(a + 1))
# TRUE
(x <- get_expr({a<-1;b<-2}))
# expression({
# a <- 1
# b <- 2
# })
(y <- expression({a<-1;b<-2}))
# expression({
# a <- 1
# b <- 2
# })
str(x)
# expression({ a <- 1 b <- 2 })
str(y)
# expression({ a <- 1 b <- 2 })
all.equal(x, y)
# TRUE
Run Code Online (Sandbox Code Playgroud)
identical(x, y)
# …
Run Code Online (Sandbox Code Playgroud) 我有一组包含空格分隔元素的字符串.我想建立一个矩阵,告诉我哪些元素是哪些字符串的一部分.例如:
""
"A B C"
"D"
"B D"
Run Code Online (Sandbox Code Playgroud)
应该给出类似的东西:
A B C D
1
2 1 1 1
3 1
4 1 1
Run Code Online (Sandbox Code Playgroud)
现在我已经有了一个解决方案,但是它作为磨拉石运行缓慢,而且我已经没有关于如何加快速度的想法:
reverseIn <- function(vector, value) {
return(value %in% vector)
}
buildCategoryMatrix <- function(valueVector) {
allClasses <- c()
for(classVec in unique(valueVector)) {
allClasses <- unique(c(allClasses,
strsplit(classVec, " ", fixed=TRUE)[[1]]))
}
resMatrix <- matrix(ncol=0, nrow=length(valueVector))
splitValues <- strsplit(valueVector, " ", fixed=TRUE)
for(cat in allClasses) {
if(cat=="") {
catIsPart <- (valueVector == "")
} else {
catIsPart <- sapply(splitValues, reverseIn, …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Windows 机器上的 postgres 服务器上安装 plpython。当我CREATE EXTENSION plpython3u;
在 postgres 中发出命令时,出现以下错误,我正在尝试查找其来源。
ERROR: could not load library "C:/Program Files/PostgreSQL/9.3/lib/plpython3.dll": The specified module could not be found.
Run Code Online (Sandbox Code Playgroud)
该文件存在,我认为这意味着 Windows 找不到它所依赖的文件之一。当我用Dependency Walker打开plpython3.dll 时,它告诉我它无法找到 GPSVC.dll。
这个丢失的dll是否可能导致CREATE EXTENSION
命令失败?我在 C:\Windows\System32 中找到了一个同名的 .dll 并将其复制到 C:\Windows\SysWOW64,但这并没有解决问题,虽然依赖步行者现在找到了 .dll,但它引发了其他几个有关具有不同 CPU 类型的模块的错误。
如何在R中创建请求因变量?例如
a <- 1
b <- a*2
a <- 2
b
# [1] 2
Run Code Online (Sandbox Code Playgroud)
但我期待结果4. R如何自动维持关系?非常感谢 解释 - 我正在尝试使用单元格之间的关系(公式或函数)创建excel spreeadsheet.R的输入用于检验csv(相同值,某些函数或公式)并仅输出值
我试图使用ggplot在一个窗口框架中对齐条形图和线图的x轴.这是我试图用它做的假数据.
library(ggplot2)
library(gridExtra)
m <- as.data.frame(matrix(0, ncol = 2, nrow = 27))
colnames(m) <- c("x", "y")
for( i in 1:nrow(m))
{
m$x[i] <- i
m$y[i] <- ((i*2) + 3)
}
My_plot <- (ggplot(data = m, aes(x = x, y = y)) + theme_bw())
Line_plot <- My_plot + geom_line()
Bar_plot <- My_plot + geom_bar(stat = "identity")
grid.arrange(Line_plot, Bar_plot)
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助.
我最近开始玩Shiny.我试图写一些东西来证明中心极限定理.我的代码如下:
ui.R:
#****************************************ui.R file code*****************************
library(shiny)
shinyUI(pageWithSidebar(headerPanel("Central Limit Theorem"),
sidebarPanel(selectInput("Distribution",
"Distribution:",
list("normal", "lognormal")),
br(),
sliderInput("sam_size",
"Sample size:",
min = 5,
max = 500,
value = 5)
),
mainPanel(tabPanel("Plot", plotOutput("plot")))
))
Run Code Online (Sandbox Code Playgroud)
server.R:
#****************************************server.R file code**************************
library(shiny)
shinyServer(function(input, output){
data <- reactive(function(){Distribution <- switch(input$Distribution,
normal = rnorm,
lognormal = rlnorm,
rnorm
)
Distribution(input$sam_size*2000)})
output$plot <- reactive(function(){
Distribution <- input$Distribution
sam_size <- input$sam_size
temp <- matrix(data(), ncol=2000)
xbars <- colMeans(temp)
hist(xbars, main=paste("Sampling Distribution of the Mean Based on a", Distribution,
"distribution with n …
Run Code Online (Sandbox Code Playgroud) r ×10
shiny ×3
arrays ×1
duplicates ×1
ggplot2 ×1
matrix ×1
numpy ×1
optimization ×1
plot ×1
plpython ×1
postgresql ×1
python ×1
row ×1
rstudio ×1
shiny-server ×1
ubuntu ×1