我正在尝试将从 Qualtrics 下载的数据导入到 R 中。它是一个 csv 文件。
但是,我遇到了两个问题。
character。不过,显然有些是date,有些是factor,有些是integer。R如何自己正确地计算出每一列的数据类?Run Code Online (Sandbox Code Playgroud)library(tidyverse) filename <- "mydata.csv" df = read_csv(filename, col_names = TRUE) Parsed with column specification: cols( .default = col_character() ) See spec(...) for full column specifications.
header分别加载变量名()和数据矩阵。不幸的是,使用这个skip = 3参数是行不通的。它说我的数据只有 1 个观察值...为什么?Run Code Online (Sandbox Code Playgroud)filename <- "mydata.csv" headers = read_csv(filename, col_names = FALSE, n_max = 1) df = read_csv(filename, skip = 3, col_names = FALSE) colnames(df)= headers …
我试图使用 kable 生成一张漂亮的表格。然而,kable 只是返回了 html 代码,而不是 r 笔记本中的表格本身(R 版本 3.5.0,Mac 上的 R 版本 1.1.453)。
```{r}
library(knitr)
dt <- mtcars[1:5,1:6]
knitr::kable(dt)
```
Run Code Online (Sandbox Code Playgroud)
R Notebook 界面和 .html 文档中显示的结果:
| | mpg| cyl| disp| hp| drat| wt|
|:-----------------|----:|---:|----:|---:|----:|-----:|
|Mazda RX4 | 21.0| 6| 160| 110| 3.90| 2.620|
|Mazda RX4 Wag | 21.0| 6| 160| 110| 3.90| 2.875|
|Datsun 710 | 22.8| 4| 108| 93| 3.85| 2.320|
|Hornet 4 Drive | 21.4| 6| 258| 110| 3.08| 3.215|
|Hornet Sportabout | 18.7| 8| 360| …Run Code Online (Sandbox Code Playgroud) 我想绘制一个合适的饼图。但是,本网站之前的大部分问题均来自stat = identity. 如何绘制一个正常的饼图,比如图 2,角度与 的比例成正比cut?我正在使用diamonds来自 ggplot2的数据框。
ggplot(data = diamonds, mapping = aes(x = cut, fill = cut)) +
geom_bar(width = 1) + coord_polar(theta = "x")
Run Code Online (Sandbox Code Playgroud)
ggplot(data = diamonds, mapping = aes(x = cut, y=..prop.., fill = cut)) +
geom_bar(width = 1) + coord_polar(theta = "x")
Run Code Online (Sandbox Code Playgroud)
ggplot(data = diamonds, mapping = aes(x = cut, fill = cut)) +
geom_bar()
Run Code Online (Sandbox Code Playgroud)