我有以下数据:
transaction <- c(1,2,3);
date <- c("2010-01-31","2010-02-28","2010-03-31");
type <- c("debit", "debit", "credit");
amount <- c(-500, -1000.97, 12500.81);
oldbalance <- c(5000, 4500, 17000.81)
evolution <- data.frame(transaction, date, type, amount, oldbalance, row.names=transaction, stringsAsFactors=FALSE);
evolution <- transform(evolution, newbalance = oldbalance + amount);
evolution我指定了row.names= transaction,但是输出给出了:
transaction date type amount oldbalance newbalance
1 1 2010-01-31 debit -500.00 5000.00 4500.00
2 2 2010-02-28 debit -1000.97 4500.00 3499.03
3 3 2010-03-31 credit 12500.81 17000.81 29501.62问题在于date字段之前的附加数字1 to 3。如何摆脱这个问题?
更新:我希望输出看起来像这样:
transaction date type amount oldbalance newbalance
1 2010-01-31 debit -500.00 5000.00 4500.00
2 2010-02-28 debit -1000.97 4500.00 3499.03
3 2010-03-31 credit 12500.81 17000.81 29501.62即包含其值的transaction列。
谢谢。
发布于 2011-12-29 01:57:07
继续@米歇尔的回答:R中的数据帧必须有行名。但是,如果要打印不带行名的数据框,可以执行以下操作:
print(evolution,row.names=FALSE)(参见?print.data.frame)
这可能是不可取的,但您可以按如下方式修改print.data.frame的定义,以屏蔽内置函数:
print.data.frame <- function(x,...) {
base:::print.data.frame(x,row.names=FALSE,...)
}发布于 2011-12-28 20:44:58
您无法摆脱它们,因为它们是R的一个特性,请参阅?row.names
发布于 2011-12-28 15:29:14
是否要省略结果data.frame中的事务列?
evolution <- data.frame(date, type, amount, oldbalance, row.names=transaction, stringsAsFactors=FALSE)有帮助吗?
https://stackoverflow.com/questions/8652615
复制相似问题