所以在R中,当我有一个由4列组成的数据框时,调用它df并且我想通过组的总和来计算比率,我可以用这样的方式:
// generate data
df = data.frame(a=c(1,1,0,1,0),b=c(1,0,0,1,0),c=c(10,5,1,5,10),d=c(3,1,2,1,2));
| a b c d |
| 1 1 10 3 |
| 1 0 5 1 |
| 0 0 1 2 |
| 1 1 5 1 |
| 0 0 10 2 |
// compute sum product ratio
df = df%>% group_by(a,b) %>%
mutate(
ratio=c/sum(c*d)
);
| a b c d ratio |
| 1 1 10 3 0.286 |
| 1 1 5 1 0.143 |
| …Run Code Online (Sandbox Code Playgroud) 我有以下数据框:
> head(table,10)
Date Open High Low Close Volume Adj.Close
1 2014-04-11 32.64 33.48 32.15 32.87 28040700 32.87
2 2014-04-10 34.88 34.98 33.09 33.40 33970700 33.40
3 2014-04-09 34.19 35.00 33.95 34.87 21597500 34.87
4 2014-04-08 33.10 34.43 33.02 33.83 35440300 33.83
5 2014-04-07 34.11 34.37 32.53 33.07 47770200 33.07
6 2014-04-04 36.01 36.05 33.83 34.26 41049900 34.26
7 2014-04-03 36.66 36.79 35.51 35.76 16792000 35.76
8 2014-04-02 36.68 36.86 36.56 36.64 14522800 36.64
9 2014-04-01 36.16 36.86 36.15 36.49 …Run Code Online (Sandbox Code Playgroud) 我想定义一个用户可以通过执行某些操作来更新的列表.我这样做了:
runApp(list(
ui=fluidPage(
h1('Example')
,textInput('txt','','Text')
,actionButton('add','add')
,verbatimTextOutput('list')
)#ui
,server=function(input,output,session) {
s.list<-reactive(isolate(d.list()))
d.list<-reactive({if (input$add == 0) return()
isolate({
list(input$txt,unlist(s.list()))
})#iso
})#rea
output$list<-renderPrint({
list(unlist(d.list()))
})#list
}#server
))#ruanApp
Run Code Online (Sandbox Code Playgroud)
但该列表无限次更新,有没有人知道如何使这项工作?
如何在结构定义中指定函数?像这样的东西:
struct Operation {
params: Vec<String>,
ops: Function<Vec<String>> -> Vec<String>,
}
Run Code Online (Sandbox Code Playgroud)
我知道语法Function<Vec<String>> -> Vec<String>不正确,但我试图指定“Operation”有一个名为 that 的字段,ops它是一个接受 aVec<String>并返回 a 的闭包Vec<String>。
我有一个用angular编写的应用程序,并通过nodejs部署到heroku.当我在家用计算机上以开发模式运行它时,一切都很棒,并且没有错误发生.但是一旦我将它传递给heroku,我在控制台上收到以下错误消息:
Mixed Content: The page at 'https://yasawebsite.herokuapp.com/#/' was loaded
over HTTPS, but requested an insecure script
'http://api.tumblr.com/v2/blog/asayorku.tumblr.com/posts?api_key=[MY SECTRET API-KEY]&callback=angular.callbacks._0'.
This request has been blocked; the content must be served over HTTPS.
Run Code Online (Sandbox Code Playgroud)
我是如何从tumblr调用我的数据的?
这就是我在做的事情:
$http.jsonp('http://api.tumblr.com/v2/blog/asayorku.tumblr.com/posts?api_key=[MY SECRET API Key]&callback=JSON_CALLBACK')
.success(function (data) {
// my data analysis process
});
Run Code Online (Sandbox Code Playgroud)
这就是我在server.js文件中设置的内容
var express = require('express')
, morgan = require('morgan')
, bodyParser = require('body-parser')
, methodOverride = require('method-override')
, app = express()
, port = process.env.PORT || 3000
, router = express.Router();
app.use(express.static(__dirname + '/dist')); …Run Code Online (Sandbox Code Playgroud) 假设我有以下代码
a<-c(1,2,3)
b<-'a'
Run Code Online (Sandbox Code Playgroud)
现在我将'b'中的字符串视为变量'a',当我将其输入到某个函数或操作中时.想象一下"treat.as.variable()"是一个真正的函数,它会这样做:
treat.as.variable(b)+c(1,2,4)
[1] 2 4 7
Run Code Online (Sandbox Code Playgroud)
是否有预定义的这样的功能?或者一般来说这样做的方法?
我从服务器获取了一些JSON值,但我不知道是否会有特定的字段。
有时我会以这种形式得到答复
{
"regatta_name":"ProbaRegatta",
"country":"Congo",
"status":"invited"
}
Run Code Online (Sandbox Code Playgroud)
有时我会收到这种形式的回复
{
"regatta_name":"ProbaRegatta",
"country":"Congo",
"status":"invited",
"vehicle": "yes"
}
Run Code Online (Sandbox Code Playgroud)
如何检查javascript对象中是否存在车钥匙?
我想将需要匹配的枚举的参数传递给参数,如下所示:
enum D {
A(i64),
B(u64),
C(u64, u64),
}
Run Code Online (Sandbox Code Playgroud)
let a = D.A(10);
println!(a.is_of(D.A)); // true
println!(a.is_of(D.B)); // false
Run Code Online (Sandbox Code Playgroud)
我知道我可以为此使用匹配规则,但是is_of出于我的目的,我希望此方法作为枚举选项的输入。