Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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 如何在读取.txt文件时避免空间_R_Read.table - Fatal编程技术网

R 如何在读取.txt文件时避免空间

R 如何在读取.txt文件时避免空间,r,read.table,R,Read.table,我试图读取一个文件,它有一列+和-,但显然与后面的空格关联。无论如何,我读了(read.csv或read.table或read\u excel我在后面找到的那个文件 例如: df = data.frame(x = c('a', 'b', 'c'), y = c('+ ', "- ", "+ ")) df x y 1 a + 2 b - 3 c + 现在,是否有一种方法专门指示不要在read.csv或read\u excel中的值后拾取空格 或者有没有办法在读取数据帧后清理空格?df

我试图读取一个文件,它有一列
+
-
,但显然与后面的空格关联。无论如何,我读了(
read.csv
read.table
read\u excel
我在后面找到的那个文件

例如:

df = data.frame(x = c('a', 'b', 'c'), y = c('+ ', "- ", "+ "))
df
  x  y
1 a + 
2 b - 
3 c + 
现在,是否有一种方法专门指示不要在
read.csv
read\u excel
中的值后拾取空格


或者有没有办法在读取数据帧后清理空格?

df$y在read.table中有一个选项,如blank.line.skip.check?read.table,不确定是否使用csv。请参阅此线程了解有关删除空格的更多信息:谢谢。
trimws()
函数在我的Rstudio中不可用。我可以使用
stringr
来实现这一点。您使用的是R,而不是Rstudio。Rstudio是一个IDE。缺少
trimws
意味着您使用的是R<3.2.0。明天升级。