While creating my data.frame, I want one of my columns to include a '/' in the column name. When I try to put it in normally, when I check my object, the '/' is replaced by a period. Here is the code I am working with. My problem is with the 'S/NS' column.
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.
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). 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:
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"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.