[R-es] ¿Cómo extraer la primera palabra de un string?

Leonardo Hernández Pérez leonardo.hernandez en etecsa.cu
Vie Jul 6 14:35:33 CEST 2012


Olvidé dejar el link.

http://en.wikibooks.org/wiki/R_Programming/Text_Processing





On 06/07/12 08:34, Leonardo Hernández Pérez wrote:
> Hola amigos:
>
> Gracias a todos por su ayuda, ya probé cada una de las soluciones, 
> esta última muy buena. También encontré buscando en Internet esta otra 
> muy sencilla que requiere el paquete Hmisc
>
> first.word("abc def ghk")
>
>
>
> Un Saludos
>
> Leonardo
>
>
>
>
>
> On 05/07/12 17:30, Carlos Ortega wrote:
>> Hola,
>>
>> Además de las alternativas válidas, esta es otra forma, utilizando la 
>> función*word() *del paquete stringr
>>
>> > library(stringr)
>> > x <- c("PC DELL P4 3.0 GHZ 512MB 150GB CD FDD LA",
>> +        "PC LTEL Celeron 1.7 GHz",
>> +        "PC CEL 1.8 ASUS P5GC-DDR2 1/320GB/DVDRW",
>> +        "PC INTEL PENTIUM 4 CPU 2.40Ghz 512MB RAM",
>> +        "PC Founder P IV 2.8 GHz 80 GB",
>> +        "Monitor ACER VIEW",
>> +        "Monitor SUN 15¨",
>> +        "COMPUTADORA P4/2.8GHZ")
>> > *word(x,1)*
>> [1] "PC"          "PC"        "PC"          "PC"
>> [5] "PC"  "Monitor"     "Monitor"     "COMPUTADORA"
>>
>> Saludos,
>> Carlos Ortega
>> www.qualityexcellence.es <http://www.qualityexcellence.es>
>>
>> El 5 de julio de 2012 22:36, Leonardo Hernández Pérez 
>> <leonardo.hernandez en etecsa.cu <mailto:leonardo.hernandez en etecsa.cu>> 
>> escribió:
>>
>>     Tengo una columna con estos datos
>>
>>     PC DELL P4 3.0 GHZ 512MB 150GB CD FDD LA
>>     PC LTEL Celeron 1.7 GHz
>>     PC CEL 1.8 ASUS P5GC-DDR2 1/320GB/DVDRW
>>     PC INTEL PENTIUM 4 CPU 2.40Ghz 512MB RAM
>>     PC Founder P IV 2.8 GHz 80 GB
>>     Monitor ACER VIEW
>>     Monitor SUN 15¨
>>     COMPUTADORA P4/2.8GHZ
>>
>>
>>       Necesito extraer la primera palabra, lo cual quedaría:
>>
>>     PC
>>     PC
>>     PC
>>     PC
>>     Monitor
>>     Monitor
>>     COMPUTADORA
>>
>>
>>       ¿Cómo Hacerlo?
>>
>>
>>     ---
>>     This message was processed by Kaspersky Mail Gateway
>>     5.6.28/RELEASE running at host imx2.etecsa.cu <http://imx2.etecsa.cu>
>>     Visit our web-site: <http://www.kaspersky.com>,
>>     <http://www.viruslist.com>
>>
>>     _______________________________________________
>>     R-help-es mailing list
>>     R-help-es en r-project.org <mailto:R-help-es en r-project.org>
>>     https://stat.ethz.ch/mailman/listinfo/r-help-es
>>
>>
>>
>>
>> -- 
>> Saludos,
>> Carlos Ortega
>> www.qualityexcellence.es <http://www.qualityexcellence.es>
>>
>>
>> ---
>> This message was processed by Kaspersky Mail Gateway 5.6.28/RELEASE running at host imx2.etecsa.cu
>> Visit our web-site:<http://www.kaspersky.com>,<http://www.viruslist.com>
>
>


------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20120706/6198edf2/attachment.html>
------------ próxima parte ------------
An embedded and charset-unspecified text was scrubbed...
Name: no disponible
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20120706/6198edf2/attachment.pl>


Más información sobre la lista de distribución R-help-es