R语言 使用spec()检索此数据的完整列规范

vql8enpb  于 2023-05-26  发布在  其他
关注(0)|答案(1)|浏览(341)

使用Rmarkdown并尝试插入数据。
这是我使用的代码块:

```{r echo=TRUE, message=TRUE }

library(tidyverse)
congress<-read_csv("womenincongress.csv")

它给了我这个

New names:
-> ...1
Rows: 49 Columns: 5
-- Column specification -------------
Delimiter: ","
chr (1): state
dbl (4): ...1, senators, represen...

i Use spec() to retrieve the full column specification for this data.
i Specify the column types or set show_col_types = FALSE to quiet this message.


我假设我希望显示所有数据,但我不确定如何使用spec函数。
z2acfund

z2acfund1#

下面是使用spec()获取完整列规格的示例:

library(readr)

# write data to a temporary file for the purposes of demonstration 
f <- file.path(tempdir(), "iris10.csv")
write.csv(iris[1:10, ], f, row.names = FALSE)

# Read data using, set show_col_types to FALSE to suppress messages
df <- read_csv(f, show_col_types = FALSE)

# You can see how each column's type is converted 
spec(df)
#> cols(
#>   Sepal.Length = col_double(),
#>   Sepal.Width = col_double(),
#>   Petal.Length = col_double(),
#>   Petal.Width = col_double(),
#>   Species = col_character()
#> )

相关问题