一、问题
当我使用以下代码读取CSV数据后,发现使用head(data)显示**[1] PK...<0 行> (或0-长度的row.names)**,如下截图所示。
R
# 尝试读取文件
data <- read.csv("C:\\Users\\11300\\Desktop\\test.csv", header = TRUE)
# 检查数据
head(data)

当在电脑上打开CSV数据查看时,发现数据并没有任何问题。

尝试解决,修改代码如下,结果仍然显示相同的问题。
R
# 尝试读取文件
data <- read.csv("C:\\Users\\11300\\Desktop\\test.csv", encoding = "UTF-8", header = TRUE)
# 检查数据
head(data)

二、问题原因
我的csv文件原本是xlsx文件,我是直接将后缀名从xlsx改为csv的,导致读不出数据。
三、解决方法
使用如下方法将xlsx文件另存为csv文件,即需要将xlsx文件另存为**CSV UTF-8(逗号分隔)(*.csv)**格式。

然后重新读取csv文件中的数据,就可以正常读取了。
R
# 尝试读取文件
data <- read.csv("C:\\Users\\11300\\Desktop\\test1.csv",header = TRUE)
# 检查数据
head(data)
