Re: [R] strsplit and sapply

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Fri, 11 Apr 2008 08:23:19 -0300

Try:

sapply(strsplit(TEXT, ';'), '[', 1)

On Fri, Apr 11, 2008 at 8:12 AM, Dennis Fisher <fisher_at_plessthan.com> wrote:

> Colleagues,
>
> I have some text:
> TEXT <- c("a", "bb;ccc", "dddd;eeeee;ffffff")
>
> I want to retrieve the portion of each element before the first
> semicolon. I can split each element using strsplit:
>
> SPLIT <- strsplit(TEXT, ";")
>
> This yields:
> > SPLIT
> [[1]]
> [1] "a"
>
> [[2]]
> [1] "bb" "ccc"
>
> [[3]]
> [1] "dddd" "eeeee" "ffffff"
>
> Now I need to access the [1] portions of [[n]] - ("a", "bb",
> "dddd"). I suspect that sapply is the correct tool here but the
> syntax eludes me. Can anyone direct me to the correct syntax?
>
> Dennis
>
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-415-564-2220
> www.PLessThan.com
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
>
https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]


______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

Received on Fri 11 Apr 2008 - 11:29:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 11 Apr 2008 - 11:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive