使用序列列表,例如
// Dependencies
var express = require("express");
var bodyParser = require("body-parser");
var mongoose = require("mongoose");
var exphbs = require("express-handlebars");
var request = require("request");
// Set mongoose to leverage built in JavaScript ES6 Promises
mongoose.Promise = Promise;
// Initialize Express
var app = express();
// Use morgan and body parser with our app
app.use(bodyParser.urlencoded({
extended: false
}));
// Make public a static dir
app.use(express.static(__dirname + "/public"));
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");
// Database configuration with mongoose
mongoose.connect("mongodb://localhost/usersdb");
var db = mongoose.connection;
// Show any mongoose errors
db.on("error", function(error) {
console.log("Mongoose Error: ", error);
});
// Once logged in to the db through mongoose, log a success message
db.once("open", function() {
console.log("Mongoose connection successful.");
});
//routes
app.get('/', function(req, res, next, error){
// Log any errors
if (error) {
console.log(error);
}
// Or send the doc to the browser as a json object
else {
res.render("index",{ title: 'Express' });
}
});
// Listen on port 27107
app.listen(process.env.PORT || 27017, function() {
console.log("App running on port 27017!");
});
是否可以创建数据框以便将序列转换为列。如,
datList <- list(One = seq(1,5, length.out = 20),
Two = seq(1,10, length.out = 20),
Three = seq(5,50, length.out = 20))
在我的“真实”数据的上下文中,我正在处理许多序列,希望可以使用datDF <- data.frame(One = datList[[1]], Two = datList[[2]], Three = datList[[3]] )
> head(datDF)
One Two Three
1 1.000000 1.000000 5.000000
2 1.210526 1.473684 7.368421
3 1.421053 1.947368 9.736842
4 1.631579 2.421053 12.105263
5 1.842105 2.894737 14.473684
6 2.052632 3.368421 16.842105
(或类似)函数,而不是手动创建所需的数据框。
答案 0 :(得分:1)
我们可以使用data.frame
datDFN <- data.frame(datList)
identical(datDF, datDFN)
#[1] TRUE