在R中使用ldply后自动重命名列

时间:2018-10-09 09:48:48

标签: r dplyr plyr

我最近遇到了this question,我成功地将其应用了。 这是我的数据:

mydf <- list(c("Gain the skills to produce original, professional, and aesthetically pleasing maps using free software", 
"Create maps with QGIS and Inkscape", "Add charts from programs like LibreOffice Calc and RStudio to maps"
), c("<U+0001F393> Aprender a utilizar Inkscape desde 0. No necesitas experiencia previa.", 
"<U+0001F58C><U+FE0F>Aprender a crear tus propios gr�ficos con Inkscape para tu sitio web, blog, p�gina de Facebook, canal de Youtube, perfil de Twitter, ...", 
"<U+0001F6E0><U+FE0F> Aprender a utilizar las herramientas de dibujo.", 
"<U+0001F58D><U+FE0F> Crear patrones con Inkscape", "<U+0001F5BC><U+FE0F> Como vectorizar una imagen bitmap a vectorial", 
"<U+0001F3A8> Como crear un dibujo vectorial a partir de una imagen"
), c("Learn how to design Vector Graphics using Inkcscape", "Learn the basics of Inkscape. No prior experience needed!"
), c("Learn how to design Vector Graphics using Inkcscape", "Learn the basics of Inkscape. No prior experience needed!"
), c("Create forms and shapes of any kind.", "Create Graphics you need or even can think of.", 
"The knowledge of Light and Shadows and their influences.", "A good understanding for third dimension.", 
"Inkscapes most important tools.", "Pictograms, UI, Cursors and alot more..."
), c("Acquire knowledge of why Vector is king.", "Understand and apply design from a client questionnaire.", 
"How to assemble and use a mood board to acquire concepts.", 
"Learn how to sketch logo design concepts like a professional.", 
"Learn all the tools of Inkscape.", "Learn how to use the Inkscape Control Bar.", 
"Discover how to use the almighty pen tool like a professional.", 
"Design almost any vector graphics in Inkscape.", "Learn how to effectively pair text with a logo design symbol.", 
"Learn how to develop a stunning logo design symbol with meaning.", 
"Learn how to kern type like a logo design professional.", "Discover how to effectively apply great taglines. ", 
"Learn how to apply colour to a logo design in a professional manner.", 
"Speak to me at any time in the Q&A! Post your work for critique to supercharge your skills!"
), "Inkscape ile logolar, afi<U+015F>ler, kurumsal kimlik �al<U+0131><U+015F>malar<U+0131>, ill�strasyonlar, karakter tasar<U+0131>mlar<U+0131>, web grafikleri, ikonlar ve �ok �e<U+015F>itli grafik tasar<U+0131>m �al<U+0131><U+015F>malar<U+0131> olu<U+015F>turabilirsiniz.  Inkscape'i temel seviyeden ba<U+015F>layarak profesyonel seviyeye kadar �<U+011F>renmek i�in kursa kaydolabilirsiniz.", 
    c("Utiliser le logiciel gratuit Inkscape", "Ma�triser les outils essentiels du logiciel", 
    "Apprendre � reproduire simplement la majorit� des logos existants", 
    "Comprendre les principales caract�ristiques des logos", 
    "Conna�tre les astuces pour cr�er son propre logo", "R�aliser simplement et rapidement son propre logo"
    ), c("Criar imagens vetoriais", "Editar imagens", "Agrupar e Desagrupar objetos", 
    "Clonagem de objetos", "Ordena��o de Objetos", "Convertendo em curvas", 
    "Texto Art�stico", "Desenhando a partir de uma imagem", "Texto Paragr�fo"
    ), c("Create colourful and interesting textures in inkscape.", 
    "Create seamless tiles in inkscape.", "Use the filter editor to modify existing filters.", 
    "Use the filter editor to create filters from scratch.", 
    "Note: the focus on this course is on learning Inkscape. Bump maps, normal maps, and specular maps will not be covered!"
    ), "Finalizado el curso, el alumno ser� capaz de conocer y desenvolverse por Inkscape con soltura, conociendo y comprendiendo todo lo necesario para el manejo de esta aplicaci�n de edici�n de gr�ficos vectoriales.", 
    c("<U+30C7><U+30B6><U+30A4><U+30F3><U+6027><U+306E><U+3088><U+3044><U+30C1><U+30E9><U+30B7><U+3084><U+540D><U+523A><U+3001><U+30D0><U+30CA><U+30FC><U+306A><U+3069><U+304C><U+6700><U+77ED><U+3067><U+4F5C><U+6210><U+3067><U+304D><U+308B><U+3088><U+3046><U+306B><U+306A><U+308A><U+307E><U+3059>", 
    "<U+3053><U+308C><U+307E><U+3067><U+5916><U+6CE8><U+3057><U+3066><U+3044><U+305F><U+30C7><U+30B6><U+30A4><U+30F3><U+7269><U+3092><U+81EA><U+5206><U+3067><U+3067><U+304D><U+308B><U+3088><U+3046><U+306B><U+306A><U+308B><U+306E><U+3067><U+3001><U+5927><U+5E45><U+306B><U+7D4C><U+8CBB><U+524A><U+6E1B><U+304C><U+3067><U+304D><U+307E><U+3059>"
    ), c("Create Icons using different techniques and Styles", 
    "Master the basics of Icon Design", "Understand the workflow and basic User Interface of Inkscape", 
    "Master Designing Vector Graphics", "Learn Inkscape Basics, without being overwhelmed by the Software!"
    ), c("Voc� vai aprender a criar personagens, plataformas, bot�es e backgrounds para o seu jogo mobile!", 
    "Voc� vai aprender a criar gr�ficos para jogos 2d adequados a motores de jogo como: Construct 2, Unity 2d, Yoyo games Game Maker, Gamesalad ou qualquer outro programa!", 
    "Voc� vai aprender a criar gr�ficos de qualidade para jogos 2d, que podem ser vendidos em mercados online!", 
    "Voc� vai aprender a usar o Inkscape, um programa de design gratuito que te permitir� criar muito mais do que apenas arte para jogos."
    ), c(" Create inspirational web design for companies of all sizes", 
    "Use Inkscape to create style tiles", "Use Bootstrap to design the steps of the sales process"
    ))

我稍后在ldply上应用了

mydf1 <- plyr::ldply(mydf, rbind)

但是,列是用数字命名的,如str()函数所示:

> str(mydf1)
'data.frame':   15 obs. of  14 variables:
 $ 1 : Factor w/ 14 levels " Create inspirational web design for companies of all sizes",..: 9 2 11 11 5 3 10 12 7 4 ...
 $ 2 : Factor w/ 12 levels "<U+0001F58C><U+FE0F>Aprender a crear tus propios gr�ficos con Inkscape para tu sitio web, blog, p�gina de Faceb"| __truncated__,..: 3 1 6 6 2 9 NA 7 5 4 ...
 $ 3 : Factor w/ 10 levels "<U+0001F6E0><U+FE0F> Aprender a utilizar las herramientas de dibujo.",..: 2 1 NA NA 6 5 NA 4 3 9 ...
 $ 4 : Factor w/ 8 levels "<U+0001F58D><U+FE0F> Crear patrones con Inkscape",..: NA 1 NA NA 2 5 NA 4 3 7 ...
 $ 5 : Factor w/ 7 levels "<U+0001F5BC><U+FE0F> Como vectorizar una imagen bitmap a vectorial",..: NA 1 NA NA 3 4 NA 2 7 6 ...
 $ 6 : Factor w/ 5 levels "<U+0001F3A8> Como crear un dibujo vectorial a partir de una imagen",..: NA 1 NA NA 4 3 NA 5 2 NA ...
 $ 7 : Factor w/ 2 levels "Discover how to use the almighty pen tool like a professional.",..: NA NA NA NA NA 1 NA NA 2 NA ...
 $ 8 : Factor w/ 2 levels "Desenhando a partir de uma imagem",..: NA NA NA NA NA 2 NA NA 1 NA ...
 $ 9 : Factor w/ 2 levels "Learn how to effectively pair text with a logo design symbol.",..: NA NA NA NA NA 1 NA NA 2 NA ...
 $ 10: Factor w/ 1 level "Learn how to develop a stunning logo design symbol with meaning.": NA NA NA NA NA 1 NA NA NA NA ...
 $ 11: Factor w/ 1 level "Learn how to kern type like a logo design professional.": NA NA NA NA NA 1 NA NA NA NA ...
 $ 12: Factor w/ 1 level "Discover how to effectively apply great taglines. ": NA NA NA NA NA 1 NA NA NA NA ...
 $ 13: Factor w/ 1 level "Learn how to apply colour to a logo design in a professional manner.": NA NA NA NA NA 1 NA NA NA NA ...
 $ 14: Factor w/ 1 level "Speak to me at any time in the Q&A! Post your work for critique to supercharge your skills!": NA NA NA NA NA 1 NA NA NA NA ...

我的问题

如何使用这种结构自动重命名列名?

MYDF_1,MYDF_2,MYDF_3 ... MYDF_14

请注意,数字应该自动放置,因为我有很多变量,每个变量代表不同的列数。

1 个答案:

答案 0 :(得分:1)

这应该做

colnames(mydf1) <- paste0("MYDF_", seq_len(ncol(mydf1))) 

根据Konrad Rudolph的建议进行了更新。