我现在有以下数据集:
data.frame(Time = 208.8639, Passes = 84.52101,
Tackles = 4.191597, Saves = 0.6672269)
#> Time Passes Tackles Saves
#> 1 208.8639 84.52101 4.191597 0.6672269
我需要将其转换为以下内容:
#> var mean
#> 1 Time 208.8639000
#> 2 Passes 84.5210100
#> 3 Tackles 4.1915970
#> 4 Saves 0.6672269
我在尝试提供列名时面临问题" var"使用"转置"功能。我尝试使用" mutate"功能也是如此。我需要使用' dplyr'功能在这里。请有人帮帮忙吗?感谢
答案 0 :(得分:1)
您可以使用以下代码:
### your data
my_df <- data.frame(Time = 208.8639, Passes = 84.52101,
Tackles = 4.191597, Saves = 0.6672269)
library(tibble)
# transpose and keep data.frame
my_df2 <- as.data.frame(t(my_df))
names(my_df2) <- "mean"
# use the tibble function
rownames_to_column(my_df2, var = "var")
var mean
1 Time 208.8639000
2 Passes 84.5210100
3 Tackles 4.1915970
4 Saves 0.6672269
答案 1 :(得分:1)
两种方式:一种使用public void addToCart (Order order)
{
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put("ProductId", order.getProductId();
values.put("ProductName", order.getProductName();
values.put("Quantity", order.getQuantity();
values.put("Price", order.getPrice();
values.put("Discount", order.getDiscount();
db.insert("OrderDetail", null, values);
}
,另一种使用reshape2::melt()
tidyr::gather()