简体   繁体   English

如何将此表变成数据框? 我正在使用 R。 试图得到它的方差分析表

[英]How do I make this table into a data frame? I'm using R. Trying to get the ANOVA table for it

在此处输入图像描述

Here's what I have, but I don't think it's right:这是我所拥有的,但我认为它不正确:

gas.test <- data.frame(gas=c(0, 14, 12, 13, 11, 17, 0, 13, 11, 10, 14, 14, 0,
                             12, 12, 13, 13, 12, 0, 11, 12, 10, 9, 8, 0),
                       Test_Car = factor(rep(c("A", "B", "C", "D", "E"), each=5)),
                       Additive = factor(rep(c(1, 2, 3, 4, 5), 5)))

I am guessing you are after either getting the matrix out of gas.test or the other way around.我猜你是在从 gas.test 中取出矩阵之后,或者反过来。

Here are both options, using pivot_wider and pivot_longer .这里有两个选项,使用pivot_widerpivot_longer

library(tidyr)
gas.test %>%
        pivot_wider(names_from = Test_Car, values_from = gas)
 # A tibble: 5 x 6 Additive AB C DE <fct> <dbl> <dbl> <dbl> <dbl> <dbl> 1 1 0 17 14 13 12 2 2 14 0 14 13 10 3 3 12 13 0 12 9 4 4 13 11 12 0 8 5 5 11 10 12 11 0
 mat %>% pivot_longer(!Additive, names_to = "Test_Cars", values_to = "gas")
 # A tibble: 25 x 3 Additive Test_Cars gas <fct> <chr> <dbl> 1 1 A 0 2 1 B 17 3 1 C 14 4 1 D 13 5 1 E 12

using spread and gather functions.使用spreadgather功能。

mat <- gas.test %>% spread(key = Test_Car, value = gas)

gas.test <- mat %>% gather(key = Test_Car, value = gas, -Additive)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 R 中将 excel 表编码为数据框。我不想导出表,我想将其编码为 R 中的数据框 - Code an excel table into a data frame in R. I don't want to export the table, I would like to code it as a data frame in R 尝试在 R 中重新排列表格。(我是初学者!)是否有某种“转置”功能? - Trying to rearrange a table in R. (I'm a beginner!) is there some sort of 'transpose' function? 如何使用 dplyr 和 rstatix 包使用来自 ANOVA 的数据表的列执行计算? - How do I perform calculations using the columns of a data table from an ANOVA using the dplyr and rstatix packages? 我正在学习 R。我想知道如何用我制作的数据集制作条形图? - I'm learning R. I was wondering how I could make a barplot with a data set I've made? R。 我正在尝试将我的数据框子集几十年。 因此,我想通过使用列的值进行子集化 - R. I am trying to subset my data frame by decades. Therefore I want to subset by using values of a column 使用 R 进行网页抓取。 我想从网站中提取一些类似数据的表格 - Web-Scraping using R. I want to extract some table like data from a website 您好,我一直在尝试为 R 中的 macd 创建交易信号。我在生成信号和具有信号的数据帧时遇到困难 - Hello, I've been trying to create a trading signal for macd in R. I'm having difficulty generating the signal and the data frame that has the signals 我正在尝试使用 R 获取矩阵中列的乘积。 我究竟做错了什么? - I'm trying to take the product of the columns in a matrix using R. What am I doing wrong? 如何在 R 中制作队列预期寿命数据表? - How do I make a cohort life expectancy data table in R? 如何为r markdown更改ANOVA输出表中的行名? - How do I change the names of rows in ANOVA output table for r markdown?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM