从.txt文件将`comment()`分配给R对象

问题描述 投票:0回答:1

我正在尝试为数据框分配注释以存储一些相关的元数据。我有一个用引号引起来的非结构化文本文件,带有多个换行符('\ n')。

WHO_comment<-read.table(file="WHO comment.txt", sep="\t")
comment(WHO)<-WHO_comment #Read in the comment from .txt due to its length
cat(comment(WHO)) #Database metadata

但是,读数以一个大的块出现,其中'\ n'读作文字字符串。用as.character()进行转换仅返回行名(即'1')。

如何正确读取此文件?

r string comments line-breaks notepad
1个回答
0
投票

只需将注释分配给对象,如下所示:

comment(data) <- "This is a comment"
© www.soinside.com 2019 - 2024. All rights reserved.