与ggplot最简单的方法是什么?
我是否需要调用prop.table或者是否有更简单的方法?
可复制的例子:
x <- c("good", "good", "bad", "bad", "bad", "bad", "perfect", "perfect", "perfect")
y <- c("exercise1", "exercise2", "exercise3", "exercise1", "exercise2", "exercise3", "exercise1", "exercise2", "exercise3")
dt <- data.frame(x, y)
ggplot(dt, aes(x, fill = y)) + geom_bar()
Run Code Online (Sandbox Code Playgroud) 我在mongodb Java教程中找到了有关如何从mongo集合中查询的信息,但是eq它们对我来说不起作用!您知道如何使用mongo和java过滤集合中的文档吗?
这是我的尝试:
package Database;
import org.bson.Document;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
public class StackOverflow {
public static void main(String[] args) {
// insert something to mongo:
final String URI = "mongodb://localhost:27017";
final String DB = "StackOverflowQuestion";
final String COLLECTION = "eqDoesntExcist";
MongoClientURI connection = new MongoClientURI(URI);
MongoClient mongo = new MongoClient(connection);
MongoDatabase database = mongo.getDatabase(DB);
MongoCollection<Document> collection = database.getCollection(COLLECTION);
Document doc = new Document("name", "Troy").append("height", 185);
collection.insertOne(doc);
doc = new …Run Code Online (Sandbox Code Playgroud) 为什么当字符串包含时该String::matches方法返回?false\n
public class AppMain2 {
public static void main(String[] args) {
String data1 = "\n London";
System.out.println(data1.matches(".*London.*")); // false
}
}
Run Code Online (Sandbox Code Playgroud) 我正在进行聚合:
iris$group <- sample(1:2, 150, T)
aggregate(Sepal.Length ~ Species + group , data = iris, FUN = function(x) c(m = mean(x), n = length(x)))
Run Code Online (Sandbox Code Playgroud)
现在我想group用变量替换:variable = "group"和聚合应该如上所述:
iris$group <- sample(1:2, 150, T)
variable = "group"
aggregate(Sepal.Length ~ Species + variable , data = iris, FUN = function(x) c(m = mean(x), n = length(x)))
Run Code Online (Sandbox Code Playgroud)
但然后发生错误.我尝试过eval,它没有帮助.
如果参数negation为真,那么condition应该否定.有没有更方便的方式来写这个?
foo <- function (x, type, negation){
if(type == 1){
condition <- x > 1
if(negation){
condition <- !condition
}
}
if(type == 2){
condition <- x == 5
if(negation){
condition <- !condition
}
}
x[condition]
}
Run Code Online (Sandbox Code Playgroud)
编辑:示例:
x <- 1:10
foo(x, 1, T) # 1
foo(x, 1, F) # 2 3 4 5 6 7 8 9 10
foo(x, 2, T) # 1 2 3 4 6 7 8 9 10
foo(x, 2, F) # …Run Code Online (Sandbox Code Playgroud)