![](/img/trans.png)
[英]How do I create a table in R with information that's not included in the data from my csv file?
[英]R, how do i create a string with the information of a table?
我有這張桌子:
> equiposcount
MOVIL PILA PORTATIL
138 1 13
我想創建一個字符串,如下所示:
"138 MOVIL, 1 PILA, 13 PORTATIL"
從那以后,我有點迷失在這里
> names(equiposcount)
[1] "MOVIL" "PILA" "PORTATIL"
是字符的類型,而不是矢量。 誰能幫我這個? 提前致謝。
我們可以將它stack
到data.frame
,將列('values','ind')與參數sep
paste
在一起並collapse
with(stack(equiposcount), paste(values, ind, sep=" ", collapse=", "))
#[1] "138 MOVIL, 1 PILA, 13 PORTATIL"
或者直接在命名向量的names
和向量本身上使用paste
paste(equiposcount, names(equiposcount), sep=" ", collapse=", ")
#[1] "138 MOVIL, 1 PILA, 13 PORTATIL"
equiposcount <- c(MOVIL = 138, PILA = 1, PORTATIL = 13)
你也可以使用Map
功能 -
> paste(Map(paste,equiposcount,names(equiposcount)),collapse = ",")
[1] "138 MOVIL,1 PILA,13 PORTATIL"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.