- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试实现用于新近度、频率和货币值(value)分析的 rfm
包,但我在“日期”转换方面遇到了问题,无法使该包正常工作。
我已经在 shiny 中尝试了下面的代码,问题似乎出在使用 reactivePoll 函数从 MySQL 导入的日期字段
我有以下数据集与包 rfm 的交易数据一起使用:
rfmdata <- tibble::tribble(
~CustomerID, ~Date, ~Revenue,
14159, "2011-07-13 12:06:00", 419.48,
14110, "2011-07-13 12:06:00", 317.4,
15530, "2011-07-13 12:15:00", 177.85,
16779, "2011-07-13 12:18:00", 660.01,
16225, "2011-07-13 12:18:00", 353.08,
12528, "2011-07-13 12:24:00", 281.71,
13089, "2011-07-13 12:27:00", 214.2,
18121, "2011-07-13 12:53:00", 23.25,
14502, "2011-07-13 13:14:00", 105.78,
12935, "2011-07-13 13:16:00", 353.09,
13149, "2011-07-13 13:20:00", 506.16,
15311, "2011-07-13 13:27:00", 152.81,
18219, "2011-07-13 13:33:00", 185.85,
12766, "2011-07-13 13:37:00", 936.48,
14088, "2011-07-13 13:56:00", -76.32,
18245, "2011-07-13 14:28:00", 330.92,
18245, "2011-07-13 14:29:00", 35.6,
13777, "2011-07-13 14:39:00", 270.9,
14221, "2011-07-13 15:04:00", 357.78,
14221, "2011-07-13 15:05:00", 17.4,
14201, "2011-07-13 15:18:00", 110.14,
18225, "2011-07-13 15:29:00", 488.4,
12415, "2011-07-13 15:30:00", 2735.16,
12415, "2011-07-13 15:31:00", 61.2,
13667, "2011-07-13 15:42:00", 305.02,
14400, "2011-07-13 15:50:00", 574.7,
17644, "2011-07-13 16:47:00", 316.85,
17644, "2011-07-13 16:48:00", 39.6,
17567, "2011-07-13 17:03:00", 461.08,
12405, "2011-07-14 08:52:00", 1710.39,
14265, "2011-07-14 09:10:00", 252.05,
17738, "2011-07-14 09:22:00", 585.62,
17738, "2011-07-14 09:23:00", 205.95,
17389, "2011-07-14 09:26:00", 561.9,
16719, "2011-07-14 09:54:00", 308.2,
13012, "2011-07-14 09:58:00", 304.92,
15125, "2011-07-14 10:08:00", 315.12,
15125, "2011-07-14 10:09:00", 49.92,
13577, "2011-07-14 10:11:00", 465.35,
17315, "2011-07-14 10:15:00", 112.81,
14426, "2011-07-14 10:19:00", -500.74,
17396, "2011-07-14 10:20:00", 791.7,
17396, "2011-07-14 10:20:00", 1960.8,
17396, "2011-07-14 10:21:00", 1037.1,
17396, "2011-07-14 10:21:00", 596.7,
17396, "2011-07-14 10:24:00", 18,
16701, "2011-07-14 10:27:00", -119.76
)
此数据来自 MySQL 数据库,每 30 分钟通过 reactivePoll 获取一次,如下所示:
con <- dbConnect(MySQL(),
user = ('root'),
password = ('ruvimboML55AMG'),
host = ('localhost'),
dbname = ('healthcare_mining'))
get_rfmData <- function(con) {
RFM_data_orders <- dbGetQuery(con, "SELECT CustomerID, Date, sum(Amount) as Revenue FROM onlineRetail WHERE CustomerID is not null Group by CustomerID, Date;")
}
# Reactive poll for rfm data every 30 min
RFM_data_orders <- reactivePoll(1800000, session,
checkFunc = function(){
print("Entered Check")
Sys.time()
print(Sys.time())
# get max date from database table to determine if data has been updated
max_date <- dbGetQuery(con, "SELECT MAX(date_updated) FROM onlineRetail as updated_last;")
return(max_date)
},
valueFunc = function(){
print("Entered Value")
Sys.time()
print(Sys.time())
get_rfmData(con)
}
)
接下来我需要创建一个数据表,它使用以下代码从 react 性轮询数据中提供 rfm 数据:
# Customer Recency, Frequency and Monetary Analytics
output$rfmAnalytics <- DT::renderDataTable({
req(credentials()$user_auth)
withProgress(message = 'Calculation in progress',
detail = 'This may take a while...', value = 0, {
for (i in 1:15) {
incProgress(1/15)
Sys.sleep(20)
}
})
analysis_date <- lubridate::as_date(today(),tz = 'CAT')
RFM_data_orders() %>%
dplyr::mutate(Date = as.Date(Date, '%m/%d/%Y %H:%M')) %>%
rfm_result <- rfm_table_order(RFM_data_orders(), CustomerID, Date, Revenue, analysis_date)
rfm_result
DT::datatable(rfm_result$rfm)
})
我收到以下错误消息:
Warning: Error in -: non-numeric argument to binary operator
这应该与“日期”字段有关,我认为它没有被转换为“日期”格式,而是保留在从 MySQL 导入的“字符”中。
最佳答案
设法找到如下解决方案:
# Store RFM Data reactively
dataRFM <- reactive({
RFM_data_orders() %>%
mutate(Date = as.Date(Date))
})
在代码中使用reactive:
# Customer Recency, Frequency and Monetary Analytics
output$rfmAnalytics <- DT::renderDataTable({
req(credentials()$user_auth)
withProgress(message = 'Calculation in progress',
detail = 'This may take a while...', value = 0, {
for (i in 1:15) {
incProgress(1/15)
Sys.sleep(20)
}
})
analysis_date <- lubridate::as_date(today(),tz = 'CAT')
rfm_result <- rfm_table_order(dataRFM(), CustomerID, Date, Revenue, analysis_date)
rfm_result
DT::datatable(rfm_result$rfm)
})
<sup>Created on 2019-08-21 by the [reprex package](https://reprex.tidyverse.org)
关于mysql - 使用 R Shiny 中的 rfm 包进行新近度、频率和货币值(value)分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57578947/
我有一个包含 34 个变量和大约 25,000 个观测值的数据集。每个观察都涉及一个特定事件。它的格式如下: no id date .... 1 363 006
我已将 R 连接到 Twitter 并使用 R 中的 searchTwitter 函数进行抓取,并清除标点符号、小写字母等结果数据。现在我正在尝试执行以下操作: 计算自 2015 年 1 月 至 20
我正在研究项目,需要可视化频谱分析以设置一些精确参数。现在,我将垃圾箱转换为屏幕空间,因为在线性空间中,较低频率的幅度被压缩在一起。这是我在C++中的代码: float windowSize = 64
我正在尝试使用MATLAB导入WAV文件并创建如下所示的图表类型。我基本上是在尝试获取频率信息并根据分贝对其进行绘制。这是我正在使用的代码,但似乎无法正确提取频率信息: [x fs]=wavread(
我有一个 GUI,可以计算字符串中第一个字母的出现次数。我希望它以列格式计算所有字母,例如: 这是我到目前为止所拥有的: import java.awt.BorderLayout; import ja
我有一个由许多变量组成的全国调查,就像这个(为了简单起见,我省略了一些变量): year id y.b sex income married pens weight 2002
我被要求报告我们客户的联系频率,即每周、每月、每季度或每年看到多少客户。 当在论坛中讨论“频率”时,它们通常是指某个值在表中存在的次数。 我可以获得客户的联系人数量:- select A.cl
我正在尝试制作一款游戏,当麦克风发出足够响亮的声音时,我的角色会射击(在 Unity 中)。但是我不知道如何开始。 感谢您的帮助! 最佳答案 您可以通过使用 AudioSource.GetOutput
尝试计算字符数并改进我的代码,我做了一些更改,而不是使用 while 循环。好奇是否有人对我如何改进我的代码以使其更专业且更便宜有任何建议? #include int countingCharact
我正在创建一个 MySQL 数据库,其中包含大量带有时间戳的条目。这些条目将附加到特定用户和另一个索引(例如博客作者和他的几个网站)。计算用户/全局每日条目图表的最佳方法是什么。 我的两种方法是使用
我创建了一项调查并将其发送出去。该调查要求用户提供电子邮件,然后要求他们从包含 8 个不同选项的下拉菜单中选择要吃哪顿饭。有些人使用同一封电子邮件多次填写调查,但食物选择不同。 我有一个如下所示的 M
我有一个 MySQL 数据库: Date Customer_ID 我怎样才能把它变成: Customer_ID | Count_Visits_Past_Week | Count_Visits_
对于非常大的数据集,如何使用 gnuplot 仅在第一个和最后一个数据点的 x 轴上放置标记/标签? 最佳答案 在 gnuplot 4.6 及更高版本中,您可以使用命令 stats 'data.dat
我正在寻找一种方法来为具有共同词根/含义的单个词生成数值概率值。 用户将使用“舞者”、“跳舞”、“跳舞”等词生成内容。 如果“dancer”被提交了 30 次,跳舞了 5 次,我只需要一个值“danc
给定一个包含如下内容的数据集: [2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 65, 75, 85, 86, 87,
我想将声音的音高绘制成图表。 目前我可以绘制幅度。下图是由 getUnscaledAmplitude() 返回的数据创建的: AudioInputStream audioInputStream = A
在 Javascript 中,我试图获取一个初始的数值数组并计算其中的元素。理想情况下,结果将是两个新数组,第一个指定每个唯一元素,第二个包含每个元素出现的次数。不过,我愿意接受有关输出格式的建议。
我正在编写一个多线程OpenMPI应用程序,使用来自多个线程的MPI_Isend和MPI_Irecv在InfiniBand RDMA的各个列之间每秒交换数百条消息。 传输量约为400-800KByte
这个站点上有很多问题,询问如何在给定频率下创建简单的正弦波。我想做的是获取阵列或列表或任何频率,然后连续连续播放它们(而不是和弦),听起来有点像旧PC扬声器。我尝试使用Console.Beep,但是它
我使用我的App捕获声音。假设此声音是正弦1 KHz声音,并且存在背景声音。如何识别此1 KHz声音出现在声音上? 我的意思是,我可以想象如何在图像中找到元素,例如,如果您要在图像上寻找黄色正方形,那
我是一名优秀的程序员,十分优秀!