R中用data()查看读取的test_data报错:data set ‘test_data’ not found
问题:执行
data(test_data)报错“data set ‘test_data’ not found” 加载数据的操作
我通过以下代码从文本文件加载数据:
test_data <- read_csv("C:/test/input.txt")
加载完成后,数据输出如下:
test_data Rows: 10 Columns: 6 -- Column specification ------------------------------------------------------------------------ Delimiter: "," chr (5): patient, handling, handling_id, registration_type, employee dttm (1): time 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. > test_data # A tibble: 10 x 6 patient handling handling_id registration_type time employee <chr> <chr> <chr> <chr> <dttm> <chr> 1 Item1 Astart approved started 2021-12-06 02:00:00 NULL 2 Item1 Astart approved completed 2021-12-06 02:30:00 NULL 3 Item1 AB approved2 started 2021-12-06 07:00:00 NULL 4 Item1 AB approved2 completed 2021-12-06 09:00:00 NULL 5 Item1 APar approved3 started 2021-12-06 05:00:00 NULL 6 Item1 APar approved3 completed 2021-12-06 14:00:00 NULL 7 Item1 APar2 approved5 started 2021-12-06 05:00:00 NULL 8 Item1 APar2 approved5 completed 2021-12-06 14:00:00 NULL 9 Item1 AEnd approved4 started 2021-12-06 20:00:00 NULL 10 Item1 AEnd approved4 completed 2021-12-06 22:00:00 NULL
遇到的错误
尝试用以下代码查看数据时:
data(test_data)
收到错误提示:
Warning message: In data(test_data) : data set ‘test_data’ not found
解决方法
data()函数的功能是加载R包内置的标准数据集,你通过read_csv()创建的test_data是当前工作环境中的自定义对象,不属于内置数据集范畴,因此data()无法找到它。- 要查看这个自定义数据框,直接输入对象名称即可:
test_data - 也可以使用其他常用的数据查看函数:
- 查看前6行数据:
head(test_data) - 查看数据结构:
str(test_data) - 生成数据汇总统计:
summary(test_data)
- 查看前6行数据:
内容的提问来源于stack exchange,提问作者steve
相关产品推荐
相关产品推荐

