列名从CSV更改为R:点而不是斜杠 [英] Names of columns change from CSV to R: dot instead of slash

查看:46
本文介绍了列名从CSV更改为R:点而不是斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在R中导入CSV文件时,列的名称会更改.它们来自"Fe/Cu"基体.到"Fe.Cu".但是我只有一个CSV文件才有这个神秘的问题.我试图重命名列

When I inport a CSV file in R the names of the columns change. They go from "Fe/Cu" to "Fe.Cu". But I have this mysterious problem only with one CSV file. I tried to rename the columns

colnames(a[12:ncol(a)])=c("Fe/Cu","Fe/Zn","Fe/Ba")

但是什么也没发生.有什么想法吗?

But nothing happens. Any ideas?

推荐答案

csv.read 函数调用中添加 check.names = FALSE 名称.这是因为默认情况下, csv.read 将检查列名是否在语法上有效,如@Asayat在逗号中所述.

Adding check.names=FALSE to csv.read function call will allow you to get the original names. This is because by default csv.read will check if column names are syntactically valid as stated by @Asayat in the commets.

来自 csv.read 文档:

check.names-逻辑:如果为TRUE,则变量中的名称检查数据帧以确保它们在语法上有效变量名.如有必要(通过make.names)对其进行调整,以便是的,并确保没有重复.

check.names - logical: If TRUE then the names of the variables in the data frame are checked to ensure that they are syntactically valid variable names. If necessary they are adjusted (by make.names) so that they are, and also to ensure that there are no duplicates.

如果您随后查看 make.names 的文档,则会发现:

If you then check for the documentation of make.names you will find:

在语法上有效的名称由字母,数字和点或给字符加下划线,并以字母或点开头一个数字.诸如".2way"之类的名称无效,保留字.

A syntactically valid name consists of letters, numbers and the dot or underline characters and starts with a letter or the dot not followed by a number. Names such as ".2way" are not valid, and neither are the reserved words.

这是@Asayat的评论.

which is what @Asayat commented.

这篇关于列名从CSV更改为R:点而不是斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆