我有一个数字向量列表,我想将它们组合成一个向量.但我无法做到这一点.该列表可以在列表元素中具有一个共同的元素.最终的矢量不应该添加两次.这是一个例子:
>lst
`1`
[1] 1 2
`2`
[2] 2 4 5
`3`
[3] 5 9 1
Run Code Online (Sandbox Code Playgroud)
我想要最终结果
>result
[1] 1 2 4 5 9 1
Run Code Online (Sandbox Code Playgroud)
我试着做以下事情,而不用担心重复:
>vec<-vector()
>sapply(lst, append,vec)
Run Code Online (Sandbox Code Playgroud)
和
>vec<-vector()
>sapply(lst, c, vec)
Run Code Online (Sandbox Code Playgroud)
他们都没有工作.有人可以帮我吗?
谢谢.
我正在尝试对数据帧进行子集化,其中我基于多个列值获得多个数据帧.这是我的例子
>df
v1 v2 v3 v4 v5
A Z 1 10 12
D Y 10 12 8
E X 2 12 15
A Z 1 10 12
E X 2 14 16
Run Code Online (Sandbox Code Playgroud)
预期的输出是这样的,我将这个数据帧拆分为基于列v1和的多个数据帧v2
>df1
v3 v4 v5
1 10 12
1 10 12
>df2
v3 v4 v5
10 12 8
>df3
v3 v4 v5
2 12 15
2 14 16
Run Code Online (Sandbox Code Playgroud)
我已经编写了一个现在正在运行的代码,但不认为这是最好的方法.必须有更好的方法来做到这一点.假设tabdata.frame具有初始数据.这是我的代码:
v1Factors<-levels(factor(tab$v1))
v2Factors<-levels(factor(tab$v2))
for(i in 1:length(v1Factors)){
for(j in 1:length(v2Factors)){
subsetTab<-subset(tab, v1==v1Factors[i] & v2==v2Factors[j], select=c("v3", "v4", …Run Code Online (Sandbox Code Playgroud) 我有一个数据框,其中包含标题
Name 0x1 1x2
Run Code Online (Sandbox Code Playgroud)
read.csv将标题更改为
Name X0x1 X1x2
Run Code Online (Sandbox Code Playgroud)
有没有办法可以避免这种情况?
谢谢.
我有一个数据框:
x <- data.frame(id = letters[1:3], val0 = 1:3, val1 = 4:6, val2 = 7:9)
# id val0 val1 val2
# 1 a 1 4 7
# 2 b 2 5 8
# 3 c 3 6 9
Run Code Online (Sandbox Code Playgroud)
在每行中,我想计算每个值的相应比例(比率).例如,对于"val0"列中的值,我想计算行方式val0 /(val0 + val1 + val2).
期望的输出:
id val0 val1 val2
1 a 0.083 0.33 0.583
2 b 0.133 0.33 0.533
3 c 0.167 0.33 0.5
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我这是最好的方法吗?这里只有三列,但可能有很多列.
我编写了一个函数来使用ggplot函数获得比例堆积条形图.现在我在这里使用列名ID.
PropBarPlot<-function(df, mytitle=""){
melteddf<-melt(df, id="ID", na.rm=T)
ggplot(melteddf, aes(ID, value, fill=variable)) +
geom_bar(position="fill") +
theme(axis.text.x = element_text(angle=90, vjust=1)) +
labs(title=mytitle)
}
Run Code Online (Sandbox Code Playgroud)
我想让它变得通用.所以我想使用列索引而不是列名.我尝试过做这样的事情.
PropBarPlot<-function(df, mytitle=""){
melteddf<-melt(df, id=names(df)[1], na.rm=T)
ggplot(melteddf, aes(names(df)[1], value, fill=variable)) +
geom_bar(position="fill") +
theme(axis.text.x = element_text(angle=90, vjust=1)) +
labs(title=mytitle)
}
Run Code Online (Sandbox Code Playgroud)
但没有用.谁能建议我怎么做?
谢谢.
我正在使用ggplot绘制比例堆积条形图.我得到的情节是这样的:

这是我正在使用的自编函数:
df <- data.frame(id=letters[1:3],val0=1:3,val1=4:6,val2=7:9, val3=2:4, val4=1:3, val5=4:6, val6=10:12, val7=12:14)
PropBarPlot<-function(df, mytitle=""){
melteddf<-melt(df, id=names(df)[1], na.rm=T)
ggplot(melteddf, aes_string(x=names(df)[1], y="value", fill="variable")) +
geom_bar(position="fill") +
theme(axis.text.x = element_text(angle=90, vjust=1)) +
labs(title=mytitle)
}
print(PropBarPlot(df))
Run Code Online (Sandbox Code Playgroud)
在这里val4并val5没有太大的不同.
但由于颜色,其中一些是无法区分的.有人能告诉我如何选择更好的颜色,以便它们可以区分吗?
谢谢.
交互式 rebase 之间有什么不同,例如:
git rebase -i HEAD~3
Run Code Online (Sandbox Code Playgroud)
并在没有-i:
git rebase HEAD~3
Run Code Online (Sandbox Code Playgroud) 我有两个数据框:
>df1
type id1 id2 id3 count1 count2 count3
a x1 y1 z1 10 20 0
b x2 y2 z2 20 0 30
c x3 y3 z3 10 10 10
>df2
id prop
x1 10
x2 5
x3 100
y1 0
y2 50
y3 80
z1 10
z2 20
z3 30
Run Code Online (Sandbox Code Playgroud)
count*就像重量一样.所以,最后我想加入表格,这TotalProp是道具和计数的加权和
例如,对于df1中的第一行 TotalProp = 10(prop for x1) * 10(count1) + 0(Prop for y1) * 20(count2) + 10(Prop for z1) * 0(count3) = 100
因此我的决赛桌看起来像这样:
>result
type …Run Code Online (Sandbox Code Playgroud) 我正在尝试升级我当前的回归基础设施以使用管道插件,我意识到有两种方法:scripted pipeline和declarative pipeline.通过多篇文章,我意识到这declarative pipeline是更具前瞻性和更强大的功能,因此我倾向于使用它.但似乎有以下限制,我不希望在我的设置中:
该jenkinsfile需求是在库中.我不想让我jenkinsfile留在代码库中.
由于jenkinsfile需要在SCM中.这是否意味着我无法测试文件中的任何修改,直到我检查到存储库.
上述任何细节都非常有用.
我在 RNN 工作。我有以下来自某个站点的代码行。如果您观察到第二层没有“returnSequence”参数。
我假设返回序列是强制性的,因为它应该返回序列。你能告诉为什么这没有定义。
第一层 LSTM:
regressor.add(LSTM(units = 30, return_sequences = True))
Run Code Online (Sandbox Code Playgroud)
第二层 LSTM:
regressor.add(LSTM(units = 30))
Run Code Online (Sandbox Code Playgroud)