我之前提过这个问题但是关于另一种编程语言.
假设我有几个词根,前缀和后缀.
roots = ["car insurance", "auto insurance"]
prefix = ["cheap", "budget"]
suffix = ["quote", "quotes"]
Run Code Online (Sandbox Code Playgroud)
Python中是否有一个简单的函数,它允许我构造三个字符向量的所有可能组合.
所以我想要一个列表或其他数据结构,它返回每个字符串的所有可能组合的以下列表.
cheap car insurance quotes
cheap car insurance quotes
budget auto insurance quotes
budget insurance quotes
...
Run Code Online (Sandbox Code Playgroud) 假设我有以下数据。我正在尝试通过 acct_id 计算每个 Buyer_id 的计数,其中 Buyer_id 包含 5。因此,对于 acct 51(它有 5 个实例并且包含一个包含 5 的实例),我要找到每个 Buyer_id 的计数(当然不包括 5)。此计数应遍历所有包含 buy_id 为 5 的 acct_id,并提供所有其他 buyer_id 的计数。
acct_id buyer_id message
51 5 success
51 13 fail
51 4 success
51 6 success
51 9 fail
53 6 fail
53 12 fail
53 4 success
57 6 fail
57 12 fail
57 4 success
57 5 success
Run Code Online (Sandbox Code Playgroud)
所以在这个例子中我最终会得到如下所示的结果
buyer_id count(*)
4 2
5 2
6 2
9 1
12 1
13 1
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助!
我的数据看起来像:
> head(ddd)
id affiliate_id affiliate_account_id source Pipeline num good bad
1 61046463 1006 69 29eada Contact Info Bad 1 FALSE TRUE
2 61046770 1006 69 344f39 Did not Reach 1 TRUE FALSE
3 61053937 1006 69 fff384 na 1 TRUE FALSE
4 61053941 1006 69 22d8b6 App Out 1 TRUE FALSE
5 61060137 1006 69 29eada No Offer 1 TRUE FALSE
6 61060221 1006 69 3fdb4f Contact Info Bad 1 FALSE TRUE
Run Code Online (Sandbox Code Playgroud)
我试图使用ddply函数汇总数据,以便我可以获得如下所示:
affiliate_id affiliate_account_id lead_count good_count bad_count good_rate …Run Code Online (Sandbox Code Playgroud) 我有一个数据框,想知道是否存在某个字符串.我想知道df [,1]中的任何值是否包含inscompany中的任何值.
df = data.frame(company=c("KMart", "Shelter"), var2=c(5,7))
if( df[,1] == inscompany ) print("YES")
inscompany <- c("21st Century Auto Insurance", "AAA Auto Insurance", "AARP Auto Insurance",
"Allstate Auto Insurance", "American Family Auto Insurance", "Eastwood Auto Insurance",
"Erie Auto Insurance", "Farmers Auto Insurance", "GMAC Auto Insurance", "Hartford Auto Insurance",
"Infinity Auto Insurance", "Mercury Auto Insurance", "Nationwide Auto Insurance", "Progressive Auto Insurance",
"Shelter Insurance Company", "Titan Auto Insurance", "Travelers Auto Insurance", "USAA Auto Insurance")
Run Code Online (Sandbox Code Playgroud)
我收到一条错误消息,它只能检查inscompany到df [,1]的第一个值.
救命!
所以我有两个数据帧,我希望将第一个数据帧中的一列与另一个数据帧中的第二列匹配.
df = data.frame(source=c("XRHxl8gq","2b790Qqv","mrgapJpQ","EsMfIbv1","ujOBob24","ujOBob24","EsMfIbv1"),
conv=c(362,247,222,160,86,65,34), all=c(19,17,26,12,22,25,11), intent=c(47,47,74,31,58,60,0))
df2 = data.frame(name=c("Bob","David","Mark","Sara","Alice","Cara","Chad","Donna","Elaine","Gary"),
source_id=c("XRHxl8gq","sr354136FH","2b790Qqv","myx645TH","mrgapJpQ","EsMfI546",
"ujOBob24","EsMfIbv1","fMHL45ts","sefihn"))
Run Code Online (Sandbox Code Playgroud)
我想要最终得到的是与source_id的匹配源,以便我可以在df中插入一个名为的新列.
> df
source conv all intent who
1 XRHxl8gq 362 19 47 Bob
2 2b790Qqv 247 17 47 Mark
3 mrgapJpQ 222 26 74 Alice
4 EsMfIbv1 160 12 31 Cara
5 ujOBob24 86 22 58 Chad
6 ujOBob24 65 25 60 Chad
7 EsMfIbv1 34 11 0 Cara
# find what values in both columns are similar.
both = intersect(df[,1], df2[,2]) # IN BOTH COLUMNS
# …Run Code Online (Sandbox Code Playgroud) 我运行以下查询时收到列ls.amount列在字段列表中的错误.
任何人都可以帮我诊断问题.
SELECT c.name, ic.keyword, COUNT(ic.keyword), SUM(ls.amount), ls.buyer FROM in_clicks AS ic
INNER JOIN ads AS a ON ic.ad_id = a.id
INNER JOIN ad_groups AS ag ON a.ad_group_id = ag.id
INNER JOIN campaigns AS c ON ag.campaign_id = c.id;
INNER JOIN leads AS l ON (ic.id = l.in_click_id)
INNER JOIN lead_status AS ls ON (l.id = ls.lead_id)
WHERE ic.create_date LIKE '%2011-08-19%' AND ic.location NOT LIKE '%Littleton%' AND discriminator LIKE '%AUTO_POST%'
GROUP BY ic.keyword ORDER BY COUNT(ic.keyword) DESC
Run Code Online (Sandbox Code Playgroud)
确切的错误消息是:
Error Code: …Run Code Online (Sandbox Code Playgroud) 我有一个关于绘制具有多个预测变量的逻辑回归模型的概率曲线的问题.我在这里发布了这个因为我想知道ggplot2特定的解决方案,并从ggplot2中的logit模型创建有用的图形.
所以这是一个例子=
library(car)
mtcars
log <- glm(vs ~ mpg + am, data=mtcars, family=binomial)
summary(log)
Run Code Online (Sandbox Code Playgroud)
这提供了logit coefs(log odds),但是我想知道如何为mpg的所有"级别"和ggplot2中的所有"级别"预测Y = 1.基本上,我如何使用ggplot2创建对解释logit模型结果有用的图?当有多个预测变量时,我特别想知道解决方案.
编辑:
我特别询问生成具有预测值或优势比的图表.