我正在尝试用一个公式创建一个sparse.model.matrix(从Matrix包中),其中两个因素之间存在相互作用.如果我的输入数据有多行,这很好,但只要我有一行,我就会得到错误:
Error in model.spmatrix(t, data, transpose = transpose, drop.unused.levels = drop.unused.levels, : cannot get a slot ("Dim") from an object of type "double"
例如:这不起作用:
f<-(mpg~as.factor(cyl)*as.factor(hp))
y<-mtcars
y$cyl<-as.factor(y$cyl)
y$hp<-as.factor(y$hp)
x<-y[1,]
myMatrix<-Matrix::sparse.model.matrix(f,x)
Run Code Online (Sandbox Code Playgroud)
但是,在两行中复制x会导致错误消失:
x<-rbind(x,x)
myMatrix<-Matrix::sparse.model.matrix(f,x)
Run Code Online (Sandbox Code Playgroud)
我已经跟踪了错误
Matrix:::Csparse_vertcat/ Matrix:::Csparse_horzcatwithin Matrix:::model.spmatrix但是我无法弄清楚这个用C编写的函数正在尝试做什么.有任何想法吗?请注意,只有在我可以确定此错误时,才会在处理两个因素之间的交互的矩阵创建时发生.
我正试图从下面的图中删除'n'图例.我猜它与stat部分有关,geom_bar()但我不完全确定它显示的是什么,因此我不确定如何删除它.我确实想要填充图例所以show.legends=FALSE不是正确的选择.很抱歉,如果这是重复的,但经过大量的查找我无法找到答案,更改scale_x_x上的图例不会覆盖它.
ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width,fill=Species))+
geom_bar(stat="sum")
Run Code Online (Sandbox Code Playgroud)
我已经开发了一个R软件包,但由于某些原因,当软件包被Roxygenised并安装时,与软件包一起使用的数据集没有正确加载.我在包的R文件夹中有一个.R脚本,如下所示
#' Score Card
#' @docType data
#' @name scoreCard
#' @aliases scoreCard
#' @format An object of class \code{data.frame} with 119 rows and 3 columns.
#' \describe{
#' \item{Category}{The Category for which an observation is made}
#' \item{Observation}{The possible responses given for each category}
#' \item{Score}{The score allocated against a response for each category}
#' }
#' @source Internal
#' @usage scoreCard
#' @keywords datasets
NULL
Run Code Online (Sandbox Code Playgroud)
这会在Roxygenise调用时为数据集创建一个.Rmd文件,但是当我尝试使用packageName::scoreCard它调用数据集时'scoreCard' is not an exported object from 'namespace:packageName' …
我希望能够删除一个 UI 元素,它是包含在 fluidRow 中的 textInput,然后将该元素(fluidRow 和 textInput)重新插入到 UI 中。但是,到目前为止,我还没有取得任何成功。
removeUI 按钮删除了所有fluidRows,包括找到按钮的那些。如果我尝试将它们放在单独的 HTML 部门中,似乎没什么区别。或者,如果它有效,则 textInput 不再位于偏移流体行中。这是我的第一个闪亮的问题,所以请保持温和,我可能犯了一些明显的错误。
# Define UI
ui <- fluidPage(
fluidRow(column(2,actionButton("rmv", "Remove UI"))),
fluidRow(column(2,actionButton("add", "Add UI"))),
tags$div(id='aTextBox', fluidRow(column(2,offset=6,
textInput("txt", "This is no longer useful"))
)
)
)
# Server logic
server <- function(input, output) {
observeEvent(input$rmv, {
removeUI(
selector = "div:has(> #aTextBox)"
)
})
observeEvent(input$add, {
insertUI(
selector = "#add",
where = "afterEnd",
ui = tags$div(id='aTextBox', fluidRow(column(2,offset=6,
textInput("txt", "This is no longer useful"))
)
)
)
})
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试将日期列表附加到列表列表中,如下所示myList。这按预期工作,只是每个列表元素中的日期元素的日期格式丢失了。有任何想法吗?
myList<-list(list("event"="A"),
list("event"="B"),
list("event"="C"))
dates<-as.Date(c("2011-06-05","2012-01-12","2016-05-09"))
outList<-mapply(FUN="c",myList,eventDate=as.list(dates),SIMPLIFY = FALSE)
Run Code Online (Sandbox Code Playgroud)
我希望实现以下目标
[[1]]
[[1]]$event
[1] "A"
[[1]]$eventDate
[1] "2011-06-05"
[[2]]
[[2]]$event
[1] "B"
[[2]]$eventDate
[1] "2012-01-12"
[[3]]
[[3]]$event
[1] "C"
[[3]]$eventDate
[1] "2016-06-09"
Run Code Online (Sandbox Code Playgroud)