Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R脚本:如何保持原始格式_R - Fatal编程技术网

R脚本:如何保持原始格式

R脚本:如何保持原始格式,r,R,我是R新手,正在努力将我的文本字符串自动转换为数字,这在我的一些文本中删除了“0” 当我读txt文件时,我注意到了这一点 dataTheFlash <- read.csv( paste(strWF,"B_Allen_Is.txt",sep=""), header = TRUE, sep=";", stringsAsFactors=FALSE ) dataTheFlash您可以使用read.csv的colClasses参数指定要保留为字符的列 dataTheFlash

我是R新手,正在努力将我的文本字符串自动转换为数字,这在我的一些文本中删除了“0”

当我读txt文件时,我注意到了这一点

dataTheFlash <- read.csv(
  paste(strWF,"B_Allen_Is.txt",sep=""),  
  header = TRUE,
  sep=";",
  stringsAsFactors=FALSE
)

dataTheFlash您可以使用
read.csv
colClasses
参数指定要保留为字符的列

dataTheFlash <- read.csv(
  paste(strWF,"B_Allen_Is.txt",sep=""),  
  header = TRUE,
  sep=";",
  stringsAsFactors=FALSE,
  colClasses = c('name_of_column'='character')
)

dataTheFlash重新导出数据,并在字符串编号列周围加引号。然后R将它们解析为字符串。请查看
?read.csv
,尤其是
colClasses
参数。在RStudio中,您可以使用“导入数据集”对话框并以交互方式选择列类。