[英]In R, how do i include a forward slash in the name of a column?
While creating my data.frame, I want one of my columns to include a '/' in the column name.在创建我的 data.frame 时,我希望我的列之一在列名中包含一个“/”。 When I try to put it in normally, when I check my object, the '/' is replaced by a period.
当我尝试正常放入时,当我检查我的 object 时,'/' 被替换为句点。 Here is the code I am working with.
这是我正在使用的代码。 My problem is with the 'S/NS' column.
我的问题是“S/NS”列。
df_3 <- data.frame(age=numeric(7800),
duration=numeric(7800),
value=numeric(7800),
'S/NS'=character(7800),
sex=character(7800),
stringsAsFactors=FALSE)
head(df_3) gives me the following output. head(df_3) 给了我以下 output。
age duration value S.NS sex
1 0 0 0
2 0 0 0
3 0 0 0
4 0 0 0
5 0 0 0
6 0 0 0
What I intended was for the column "N.NS" to appear as "N/NS" (smoking/non-smoking).我的意图是让“N.NS”列显示为“N/NS”(吸烟/不吸烟)。 I have tried fiddling around with the quotation marks, putting in a backslash escape before the forward slash, and some fruitless google searches.
我曾尝试摆弄引号,在正斜杠之前放置一个反斜杠转义,以及一些徒劳的谷歌搜索。 Thanks in advance.
提前致谢。
You can use check.names = F
to disable name checking:您可以使用
check.names = F
禁用名称检查:
df_3 <- data.frame(age=numeric(7800),
duration=numeric(7800),
value=numeric(7800),
'S/NS'=character(7800),
sex=character(7800),
stringsAsFactors=FALSE,check.names = F)
> colnames(df_3)
[1] "age" "duration" "value" "S/NS" "sex"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.