我有以下数据集:
df<-data.frame (fact= c("a,b,c,d","f,g,h,v"), value = c("0,1,0,1" , "0,0,1,0"))
Run Code Online (Sandbox Code Playgroud)
这是数据:
fact value
1 a,b,c,d 0,1,0,1
2 f,g,h,v 0,0,1,0
Run Code Online (Sandbox Code Playgroud)
我希望在值为1时拆分它.所以,我的理想输出是:
fact value
1: a,b 0,1
2: c,d 0,1
3: f,g,h 0,0,1
4: v 0
Run Code Online (Sandbox Code Playgroud)
首先,我想我可能会找到一种使用方式cut:
cut(as.numeric(strsplit(as.character(df$value), split = ",")), breaks =1)
Run Code Online (Sandbox Code Playgroud)
但我的尝试都没有结束.
我有以下输入
#mydata
ID variable1 variable2
1 a,b,c,d c,a
2 g,f,h h
3 p,l,m,n,c c,l
Run Code Online (Sandbox Code Playgroud)
我想从variable1中减去varible2的字符串,我想得到以下输出?
#Output
ID Output
1 b,d
2 g,f
3 p,m,n
Run Code Online (Sandbox Code Playgroud)
#dput
structure(list(ID = 1:3, variable1 = structure(1:3, .Label = c("a,b,c,d",
"g,f,h", "p,l,m,n,c"), class = "factor"), variable2 = structure(c(1L,
3L, 2L), .Label = c("c,a", "c,l", "h"), class = "factor")), .Names = c("ID",
"variable1", "variable2"), class = "data.frame", row.names = c(NA,
-3L))
Run Code Online (Sandbox Code Playgroud) 我将a zoo time series转换为数据框,R日期成为数据框的索引.有没有办法将日期表示为数据框中的普通列?
monthly_df <- data.frame(monthly_zoo)
head(monthly_zoo)
Run Code Online (Sandbox Code Playgroud)

head(monthly_df)
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用Python API创建Bigquery表.
from google.cloud import bigquery
bigquery_client = bigquery.Client(project="myproject")
dataset = bigquery_client.dataset("mydataset")
table = dataset.table("mytable")
table.create()
Run Code Online (Sandbox Code Playgroud)
我一直收到这个错误
AttributeError:'TableReference'对象没有属性'create'
有谁有想法吗?
我希望从Legacy SQL迁移到Standard SQL
我在Legacy SQL中有以下代码
SELECT
hits.page.pageTitle
FROM [mytable]
WHERE hits.page.pageTitle contains '%'
Run Code Online (Sandbox Code Playgroud)
我在标准SQL中尝试过这个:
SELECT
hits.page.pageTitle
FROM `mytable`
WHERE STRPOS(hits.page.pageTitle, "%")
Run Code Online (Sandbox Code Playgroud)
但它给了我这个错误:
错误:无法访问类型为ARRAY>的值[4:21]的字段页面
我希望根据他们的星期来标记我的数据。这是我的数据:
df2 <- structure(list(Order_Date = structure(c(16735, 16805, 16753,
16830, 17075, 17009, 17085, 16740, 16891, 16750, 16820, 16849,
16906, 16929, 16746, 16731, 16786, 16873, 16895, 16931), class = "Date")), .Names = "Order_Date", row.names = c(NA,
-20L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)
我试图根据一周(第0周,第1周和....)为它们添加标签,我希望在一周后将数据分组
我尝试了这个:
# order by data
library (dplyr)
df2<- arrange(df2, Order_Date)
# label them by week
$df2$week <- cumsum(weekdays(df2$Order_Date) == "Friday")
Run Code Online (Sandbox Code Playgroud)
它没有给我正确的结果,并且我得到以下输出,这很奇怪
Order_Date week
1 2015-10-27 0
2 2016-01-05 0
3 2015-11-14 0
4 2016-01-30 0
5 2016-10-01 0
6 2016-07-27 0 …Run Code Online (Sandbox Code Playgroud) 如何从数据末尾删除"/".我们假设这是我的数据
#input
ID page
1 www.example.com/, ww.example.com/flight, www.example.com/flight/
2 www.example.com/, ww.example.com/flight
Run Code Online (Sandbox Code Playgroud)
我希望从那些拥有最后一个角色的人那里删除"/",我的输出就是那样
#output
ID page
1 www.example.com, ww.example.com/flight, www.example.com/flight
2 www.example.com, ww.example.com/flight
Run Code Online (Sandbox Code Playgroud) 我有以下数据集:
mydata<- data.frame(Factors= c("a,b" , "c,d" , "a,c"), Valu = c ("2,3" , "7,8" , "9,1"))
Factors Valu
1 a,b 2,3
2 c,d 7,8
3 a,c 9,1
Run Code Online (Sandbox Code Playgroud)
我希望转换为具有以下因素的所有值的以下内容:
a b c d
2 2 7 7
3 3 8 8
9 9
1 1
Run Code Online (Sandbox Code Playgroud)
我需要一个数据透视表.但是我需要准备数据然后使用melt并dcast获得我想要的输出:准备数据的失败尝试之一是:
mydata2 <- cSplit(mydata, c("Factors","Valu") , ",", "long")
Run Code Online (Sandbox Code Playgroud)
但他们失去了联系.
我遵循了使用makeCluster 函数的这条指令,但它似乎不适用于 Windows
primary <- '192.168.1.235'
machineAddresses <- list(
list(host=primary,user='johnmount',
ncore=4),
list(host='192.168.1.70',user='johnmount',
ncore=4)
)
spec <- lapply(machineAddresses,
function(machine) {
rep(list(list(host=machine$host,
user=machine$user)),
machine$ncore)
})
spec <- unlist(spec,recursive=FALSE)
parallelCluster <- parallel::makeCluster(type='PSOCK',
master=primary,
spec=spec)
print(parallelCluster)
Run Code Online (Sandbox Code Playgroud) 我需要创建一个列表如下:
A = list(1,2,3,4)
Run Code Online (Sandbox Code Playgroud)
列表元素的数量存储在变量 X 中(本例中 X=4)。我尝试使用以下脚本但得到不同的输出
A = list(seq (1,X,1))
Run Code Online (Sandbox Code Playgroud)
我得到输出
[[1]]
[1] 1 2 3 4
Run Code Online (Sandbox Code Playgroud)
………………………………………………………………………………………………………………………………………………………… …………
我需要如下输出
[[1]]
[1] 1
[[2]]
[1] 2
[[3]]
[1] 3
[[4]]
[1] 4
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助
我在 Weka 中使用 Apriori 算法进行关联规则挖掘。我知道对每个规则的支持等于 (occurrence / total-rules )。Weka 给了我出现的次数。但是我怎么知道规则的数量呢?