[R] Trying to use pipes in R
arun
smartpink111 at yahoo.com
Wed Sep 12 20:07:43 CEST 2012
Hi,
If you want to just count the words in R, try this:
vec1<-c("uno dos tres", "cuatro cinco", "seis")
#get individual word count within quotes
res1<-unlist(lapply(strsplit(vec1, " "),length))
res1
#[1] 3 2 1
#get whole word count
length(unlist(strsplit(vec1, " ")))
#[1] 6
----- Original Message -----
From: Julio Sergio Santana <juliosergio at gmail.com>
To: r-help at r-project.org
Cc:
Sent: Wednesday, September 12, 2012 1:40 PM
Subject: [R] Trying to use pipes in R
Hi,
I'm trying to use pipes in R. By now, I could launch the linux command "wc"
(to count words from a text), but
I don't know how to capture the results, say in a vector of chars...
Here is the R code I'm trying:
:> f <- pipe("wc", open="w")
:> writeLines(c("uno dos tres", "cuatro cinco", "seis"), f)
:> close(f)
: 3 6 31
The result is just displayed but I couldn't put the result into a R
variable.
Do you have any comments on this?
Thanks,
-- Sergio.
[[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.
More information about the R-help
mailing list