2017-08-04 87 views
-1

我想将一个列分成两列。Skript和控制台之间的区别

当我在控制台下面添加代码时表示该列已被拆分。

> separate(refine, "Product code/number", into = c("product code", "number"), sep = "-") 
# A tibble: 25 x 9 
    company `product code` number    address city   country    
    name 
* <chr>   <chr> <chr>    <chr> <chr>   <chr>   
<chr> 
1 philips    p  5 Groningensingel 147 arnhem the netherlands 
dhr p. jansen 
2 philips    p  43 Groningensingel 148 arnhem the netherlands 
dhr p. hansen 
3 philips    x  3 Groningensingel 149 arnhem the netherlands 
dhr j. Gansen 
4 philips    x  34 Groningensingel 150 arnhem the netherlands 
dhr p. mansen 
5 philips    x  12 Groningensingel 151 arnhem the netherlands 
dhr p. fransen 
6 philips    p  23 Groningensingel 152 arnhem the netherlands 
dhr p. franssen 

存在的问题是,当我检查结果的列并没有被分割。

+1

您有拼错的代码:将'',sep =“ - ”))''改为'...,)sep =“ - ”)' –

+0

感谢您的回答。 – Hadsga

+0

不过,我有同样的问题。 – Hadsga

回答

0

您将永远不会在rstudio的脚本部分看到输出...或者在.R脚本文件中看到输出。该脚本只存储这些命令。 输出可以在控制台中看到,并且可以作为对象存储在环境中。在rstudio中,您可以通过命令View()查看环境和某些类型的输出。 看看rstudio的小抄:Rstudio.pdf

0

你没有分配结果。 separate不会修改现有变量refine(R中的几个函数会修改它们的参数)。它返回一个新的表与拆分列。您需要将结果分配到一个新的(或现有的)名称:

result = separate(refine, "Product code/number", into = c("product code", "number"), sep = "-") 

而不是创建一个新的变量(result),你也可以覆盖refinerefine = separate(refine, …))虽然我一般会建议不要修改现有的变量。

与您的问题标题相反,R脚本和R控制台之间的行为没有区别。这是一个基本的,普遍的R行为。

+0

非常感谢! – Hadsga