2017-08-04 84 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