Re: [R] How Can I Execute a String Expression?

2017-06-12 Thread Jeff Newmiller
R is not a very good macro language... I recommend against this strategy.

We could be more concrete in offering alternatives if you were a little more 
complete in your reproducible example [1][2][3]. What variations exactly were 
you thinking of? What kind of data are you working with? The way you read in 
the data can make a big difference in how effectively you analyze it. (Not 
asking for your actual data... just a fake version of it.)

[1] 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

[2] http://adv-r.had.co.nz/Reproducibility.html

[3] https://cran.r-project.org/web/packages/reprex/index.html
-- 
Sent from my phone. Please excuse my brevity.

On June 12, 2017 6:55:40 PM PDT, Donald Macnaughton  wrote:
>I have the string ggstr that I've built with string manipulation:
>
>ggstr =  "ggplot(df1, aes(x,y)) + geom_smooth(se=FALSE, span=0.01)"
>
>Assuming df1 is properly defined, this string will execute properly if
>I
>submit it manually without the quotes. How can execute the command as a
>string, so that I can run it repeatedly (with minor modifications) in a
>loop?  Presumably, it would be something like:
>
>execute(ggstr)
>
>Thanks for your help,
>
>Don Macnaughton
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] How Can I Execute a String Expression?

2017-06-12 Thread Bert Gunter
eval(parse(text = yourstring))  # your string must be  quoted, because
that's what a string is.

But  don't do this! (usually)

install.packages("fortunes") ## if not already downloaded and installed
library("fortunes")
fortune(106)

See ?substitute and ?bquote for perhaps better ways to proceed.

Cheers,
Bert
Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Jun 12, 2017 at 6:55 PM, Donald Macnaughton  wrote:
> I have the string ggstr that I've built with string manipulation:
>
> ggstr =  "ggplot(df1, aes(x,y)) + geom_smooth(se=FALSE, span=0.01)"
>
> Assuming df1 is properly defined, this string will execute properly if I
> submit it manually without the quotes. How can execute the command as a
> string, so that I can run it repeatedly (with minor modifications) in a
> loop?  Presumably, it would be something like:
>
> execute(ggstr)
>
> Thanks for your help,
>
> Don Macnaughton
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] How Can I Execute a String Expression?

2017-06-12 Thread Rolf Turner


On 13/06/17 13:55, Donald Macnaughton wrote:


I have the string ggstr that I've built with string manipulation:

ggstr =  "ggplot(df1, aes(x,y)) + geom_smooth(se=FALSE, span=0.01)"

Assuming df1 is properly defined, this string will execute properly if I
submit it manually without the quotes. How can execute the command as a
string, so that I can run it repeatedly (with minor modifications) in a
loop?  Presumably, it would be something like:

execute(ggstr)

Thanks for your help.


eval(parse(text = ggstr))

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] How Can I Execute a String Expression?

2017-06-12 Thread Donald Macnaughton
I have the string ggstr that I've built with string manipulation:

ggstr =  "ggplot(df1, aes(x,y)) + geom_smooth(se=FALSE, span=0.01)"

Assuming df1 is properly defined, this string will execute properly if I
submit it manually without the quotes. How can execute the command as a
string, so that I can run it repeatedly (with minor modifications) in a
loop?  Presumably, it would be something like:

execute(ggstr)

Thanks for your help,

Don Macnaughton

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] replacement has *** rows, data has ***

2017-06-12 Thread William Dunlap via R-help
This can happen if there are rows containing missing values (NA's) in the
data used to fit the model.  Use na.action=na.exclude when fitting the
model instead of the default na.action=na.omit to make the prediction
vector line up with the input data instead of lining up with the input data
after the NA-rows have been dropped.

E.g.,

> d <- data.frame(y=1:10, x=log2(c(1,2,NA,4:10)))
> fitDefault <- lm(y ~ x, data=d)
> fitNaExclude <- lm(y ~ x, data=d, na.action=na.exclude)
> length(predict(fitDefault))
[1] 9
> length(predict(fitNaExclude))
[1] 10
> predict(fitNaExclude)
 1  2  3  4  5  6
 7  8  9 10
-0.2041631  2.4602537 NA  5.1246704  5.9824210  6.6832543
 7.2758004  7.7890872  8.2418382  8.6468378


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, Jun 12, 2017 at 1:32 PM, Manqing Liu  wrote:

> Hi all,
>
> I created a predicted variable based on a model, but somehow not all
> observations have a predicted value. When I tired to add the predicated
> value to the main data set (data$pr <- pr) , it said:
> replacement has 34333 rows, data has 34347.
> Do you know how to solve that?
>
> Thanks,
> Manqing
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] replacement has *** rows, data has ***

2017-06-12 Thread David Winsemius

> On Jun 12, 2017, at 1:32 PM, Manqing Liu  wrote:
> 
> Hi all,
> 
> I created a predicted variable based on a model, but somehow not all
> observations have a predicted value. When I tired to add the predicated
> value to the main data set (data$pr <- pr) , it said:
> replacement has 34333 rows, data has 34347.
> Do you know how to solve that?
> 
> Thanks,
> Manqing
> 
>   [[alternative HTML version deleted]]

First, you should read the Posting Guide. Then you should read the help page 
for ?predict. 

Only then should  you write a follow-up email (in plain text) with code that 
constructs a simple example using whatever method was used to construct this 
`pr` variable and  provide enough information to support a sensible answer.
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] replacement has *** rows, data has ***

2017-06-12 Thread Manqing Liu
Hi all,

I created a predicted variable based on a model, but somehow not all
observations have a predicted value. When I tired to add the predicated
value to the main data set (data$pr <- pr) , it said:
replacement has 34333 rows, data has 34347.
Do you know how to solve that?

Thanks,
Manqing

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R-es] Agregar a un data.frame de manera automatica

2017-06-12 Thread Carlos Ortega
Hola,

Sí, la asignación que haces lo pones en una función.
Y luego usas "apply()" aplicándolo sobre "datos" y por cada fila...

Seria algo así como:

apply(datos, 1, my_funcion)

Saludos,
Carlos Ortega
www.qualityexcellence.es

El 12 de junio de 2017, 12:39, Jesús Para Fernández <
j.para.fernan...@hotmail.com> escribió:

> Me autocontesto, hacinedolo de la siguiente manera:
>
>
> for(i in 1:240) {
>
>   df[paste("inicio.refri", i, sep = ".")]<-datos[which.max(datos[,
> 109+i]),"LogDateTime"]
>
> }
>
>
>
> No hace falta usar el assing ni similares. Para nota, ¿se podria hacer con
> un lapply o similares?? y evitar usar el for?
>
> Gracias
>
> Jesús
>
> 
> De: R-help-es  en nombre de Jesús Para
> Fernández 
> Enviado: lunes, 12 de junio de 2017 11:58
> Para: r-help-es@r-project.org
> Asunto: [R-es] Agregar a un data.frame de manera automatica
>
> Buenas,
>
>
> Tengo un monton de variables que quiero meter en un data.frame.
>
>
> Las variables las he ido extrayendo de la siguiente manera
>
> for(i in 1:240) {
>   #saco el inicio de cada refrigeracion
>   aux1 <- paste("inicio.refri", i, sep = ".")
>   assign(aux1,datos[which.max(datos[,109+i]),"LogDateTime"])
>
> }
>
>
> Y quiero buscar una funcion que me permita meter esas 240 inicio.refri1,
> inicio.refri.240, en un data.frame como columnas, no como filas.
>
> �Como puedo hacerlo de manera autom�tica?
>
>
> Gracias!!!
> Jes�s
>
> [[alternative HTML version deleted]]
>
>
> [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es




-- 
Saludos,
Carlos Ortega
www.qualityexcellence.es

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R-es] Paralelizar R en windows

2017-06-12 Thread Carlos Ortega
Hola,

Aquí tienes una forma:
https://stackoverflow.com/questions/27051856/reading-multiple-files-quickly-in-r

Saludos,
Carlos Ortega
www.qualityexcellence.es

El 12 de junio de 2017, 15:38, Jesús Para Fernández <
j.para.fernan...@hotmail.com> escribió:

> Buenas,
>
> Quiero paralelizar R en windows para hacer una ingesta de ficheros csv. En
> una carpeta tengo 1000 ficheros y quiero ir haciendo lo siguiente:
>
> library(parallel)
>
> preprocesar<-function(inicio,fin){
>
> archivos<-list.files()
>
> for(i in inicio,fin){
> datos<-read.table(archivos[j],header=T,dec=",",sep=";")
>
>
> }
>
> }
>
>
> tasks <- list(
>   job1 = preprocesar(1,2),
>   job2 = preprocesar(3,4),
>   job3 = preprocesar(5,6)
> )
>
> out <- mclapply(
>   tasks,
>   function(f) f(),
> mc.cores=4
> )
>
>
>
> pero me da error, al ser windows me dice que no se puede paralelizar 
> alguna idea???
>
> Gracias chicos!!!
>
>
>
> [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>



-- 
Saludos,
Carlos Ortega
www.qualityexcellence.es

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Paths in knitr

2017-06-12 Thread Yihui Xie
Will there be anything wrong if you do not set these options?

Regards,
Yihui
--
https://yihui.name


On Mon, Jun 12, 2017 at 2:24 AM,   wrote:
> Hi Yihui,
> Hi Duncan,
>
> I corrected my typo. Unfortunately knitr did not find my plots in the
> directory where they reside which is different from the Rmd document.
>
> The documentation of knitr says:
>
> base.dir: (NULL) an absolute directory under which the plots are generate
> root.dir: (NULL) the root directory when evaluating code chunks; if NULL,
> the directory of the input document will be used
>
> From that description I thought, if the base.dir can be used for writng
> plots, it is then also used for reading plots if set? No, it is not.
> If I set the root directory to the plots/graphics directory will knitr
> then find my plots? No, it does not.
>
> Reading blog posts my thoughts looked not so strange to me, e.g.
> https://philmikejones.wordpress.com/2015/05/20/set-root-directory-knitr/.
> Unfortunately, it does not work for me.
>
> I am using a RStudio project file. Could it be that this interferes which
> the knitr options?
>
> I tried the solution that Duncan suggested:
>
> c_path_plots <-
> "H:/2017/Analysen/Kundenzufriedenheit/Auswertung/results/graphics
>
> `r knitr::include_graphics(file.path(c_path_plots,
> "email_distribution_pie.png"))`
>
> This solution works fine. I will go with it for this project as I have to
> finish my report soon.
>
> I read Hadley's book on bulding R Packages (
> https://www.amazon.de/R-Packages-Hadley-Wickham/dp/1491910593) and found
> it quite complicated and time consuming to build one. Thus I did not try
> yet to build my own packages. At the end of last week I heard from another
> library (http://reaktanz.de/R/pckg/roxyPackage/) which shall make building
> packages much easier. I plan to try that shortly.
>
> On my path to become better in analytics using R, I will try to use
> modules of Rmd files which can then easily be integrated into a Rmd
> report. I have yet to see how I can include these file into a complete
> report.
>
> Kind regards
>
> Georg
>
>
> - Weitergeleitet von Georg Maubach/WWBO/WW/HAW am 12.06.2017 08:47
> -
>
> Von:Yihui Xie 
> An: g.maub...@gmx.de,
> Kopie:  R Help 
> Datum:  09.06.2017 20:53
> Betreff:Re: [R] Paths in knitr
> Gesendet von:   "R-help" 
>
>
>
> I'd say it is an expert-only option. If you do not understand what it
> means, I strongly recommend you not to set it.
>
> Similarly, you set the root_dir option and I don't know why you did it,
> but
> it is a typo anyway (should be root.dir).
>
> Regards,
> Yihui
> --
> https://yihui.name
>
> On Fri, Jun 9, 2017 at 4:50 AM,  wrote:
>
>> Hi Yi,
>>
>> many thanks for your reply.
>>
>> Why I do have to se the base.dir option? Cause, to me it is not clear
> from
>> the documentation, where knitr looks for data files and how I can adjust
>> knitr to tell it where to look. base.dir was a try, but did not work.
>>
>> Can you give me a hint where I can find information/documentation on
> this
>> path issue?
>>
>> Kind regards
>>
>> Georg
>>
>>
>> > Gesendet: Donnerstag, 08. Juni 2017 um 15:05 Uhr
>> > Von: "Yihui Xie" 
>> > An: g.maub...@weinwolf.de
>> > Cc: "R Help" 
>> > Betreff: Re: [R] Paths in knitr
>> >
>> > Why do you have to set the base.dir option?
>> >
>> > Regards,
>> > Yihui
>> > --
>> > https://yihui.name
>> >
>> >
>> > On Thu, Jun 8, 2017 at 6:15 AM,   wrote:
>> > > Hi All,
>> > >
>> > > I have to compile a report for the management and decided to use
>> RMarkdown
>> > > and knitr. I compiled all needed plots (using separate R scripts)
>> before
>> > > compiling the report, thus all plots reside in my graphics
> directory.
>> The
>> > > RMarkdown report needs to access these files. I have defined
>> > >
>> > > ```{r setup, include = FALSE}
>> > > knitr::opts_knit$set(
>> > >   echo = FALSE,
>> > >   xtable.type = "html",
>> > >   base.dir = "H:/2017/Analysen/Kundenzufriedenheit/Auswertung",
>> > >   root_dir = "H:/2017/Analysen/Kundenzufriedenheit/Auswertung",
>> > >   fig.path = "results/graphics")  # relative path required, see
>> > > http://yihui.name/knitr/options
>> > > ```
>> > >
>> > > and then referenced my plot using
>> > >
>> > > 
>> > >
>> > > because I want to be able to customize the plotting attributes.
>> > >
>> > > But that fails with the message "pandoc.exe: Could not fetch
>> > > email_distribution_pie.png".
>> > >
>> > > If I give it the absolute path
>> > > "H:/2017/Analysen/Kundenzufriedenheit/Auswertung/results/
>> graphics/email_distribution_pie.png"
>> > > it works fine as well if I copy the plot into the directory where
> the
>> > > report.RMD file resides.
>> > >
>> > > How can I tell knitr to fetch the ready-made plots from the graphics
>> > > directory?
>> > >
>> > > Kind regards
>> > >
>> > > Georg
>>

Re: [R] plotting gamm results in lattice

2017-06-12 Thread Duncan Mackay
Hi Maria

If you have problems just start with a small model with predictions and then 
plot with xyplot
the same applies to xyplot
Try 

library(gamm4)

spring <- dget(file = "G:/1/example.txt")
 str(spring)
'data.frame':   11744 obs. of  11 variables:
 $ WATERBODY_ID  : Factor w/ 1994 levels "GB102021072830",..: 1 1 2 2 2 
3 3 3 4 4 ...
 $ SITE_ID   : int  157166 157166 1636 1636 1636 1635 1635 1635 
134261 1631 ...
 $ Year  : int  2011 2014 2013 2006 2003 2002 2013 2005 2013 
2006 ...
 $ Q95   : num  100 100 80 80 80 98 98 98 105 105 ...
 $ LIFE.OE_spring: num  1.02 1.03 1.02 1.06 1.06 1.07 1.12 1.05 1.14 
1.05 ...
 $ super.end.group   : Factor w/ 6 levels "B","C","D","E",..: 1 1 3 3 3 2 2 
2 4 4 ...
 $ X.urban.suburban  : num  0 0 0.07 0.07 0.07 0.53 0.53 0.53 8.07 8.07 ...
 $ X.broadleaved_woodland: num  2.83 2.83 10.39 10.39 10.39 ...
 $ X.CapWks  : num  0 0 0 0 0 0 0 0 0 0 ...
 $ Hms_Poaching  : int  0 0 10 10 10 0 0 0 0 0 ...
 $ Hms_Rsctned   : int  0 0 0 0 0 0 0 0 0 0 ...

model<-
gamm4(LIFE.OE_spring~s(Q95, 
by=super.end.group)+Year+Hms_Rsctned+Hms_Poaching+X.broadleaved_woodland 
+X.urban.suburban+X.CapWks, data=spring,
  random=~(1|WATERBODY_ID/SITE_ID))
Warning message:
Some predictor variables are on very different scales: consider rescaling

# plot(model$gam, page=1, font.lab=2, xlab="Residual Q95")

M <-predict(model$gam,type="response",se.fit=T)

# joining the dataset and the predictions keep it "in house" and on path
springP = cbind(spring, M)
springP$upper = with(springP,fit+1.96*se.fit)
springP$lower = with(springP,fit-1.96*se.fit)
str(springP)
'data.frame':   11744 obs. of  15 variables:
 $ WATERBODY_ID  : Factor w/ 1994 levels "GB102021072830",..: 1 1 2 2 2 
3 3 3 4 4 ...
 $ SITE_ID   : int  157166 157166 1636 1636 1636 1635 1635 1635 
134261 1631 ...
 $ Year  : int  2011 2014 2013 2006 2003 2002 2013 2005 2013 
2006 ...
 $ Q95   : num  100 100 80 80 80 98 98 98 105 105 ...
 $ LIFE.OE_spring: num  1.02 1.03 1.02 1.06 1.06 1.07 1.12 1.05 1.14 
1.05 ...
 $ super.end.group   : Factor w/ 6 levels "B","C","D","E",..: 1 1 3 3 3 2 2 
2 4 4 ...
 $ X.urban.suburban  : num  0 0 0.07 0.07 0.07 0.53 0.53 0.53 8.07 8.07 ...
 $ X.broadleaved_woodland: num  2.83 2.83 10.39 10.39 10.39 ...
 $ X.CapWks  : num  0 0 0 0 0 0 0 0 0 0 ...
 $ Hms_Poaching  : int  0 0 10 10 10 0 0 0 0 0 ...
 $ Hms_Rsctned   : int  0 0 0 0 0 0 0 0 0 0 ...
 $ fit   : num [1:11744(1d)] 1.03 1.04 1.04 1.02 1.01 ...
  ..- attr(*, "dimnames")=List of 1
  .. ..$ : chr  "1" "2" "3" "4" ...
 $ se.fit: num [1:11744(1d)] 0.00263 0.00266 0.00408 0.00408 
0.00411 ...
  ..- attr(*, "dimnames")=List of 1
  .. ..$ : chr  "1" "2" "3" "4" ...
 $ upper : num [1:11744(1d)] 1.03 1.04 1.05 1.03 1.02 ...
  ..- attr(*, "dimnames")=List of 1
  .. ..$ : chr  "1" "2" "3" "4" ...
 $ lower : num [1:11744(1d)] 1.02 1.03 1.03 1.01 1 ...
  ..- attr(*, "dimnames")=List of 1
  .. ..$ : chr  "1" "2" "3" "4" ...

# this produces a mess of lines for the upper and lower
xyplot(fitted(model$gam) ~ Q95 |super.end.group, data = springP,
   lower = springP$lower,
   upper = springP$upper,
   subscripts = TRUE,
   panel = function(x,y, upper, lower, subscripts, ...){
  panel.xyplot(x,y, type="smooth")
  panel.xyplot(x[order(x)], upper[subscripts][order(x)], lty=2, 
col="red")
  panel.xyplot(x[order(x)], lower[subscripts][order(x)], lty=2, 
col="red")
  #panel.loess(x,y,...) #  have not tried to fix these lines- 
depends on what you want to do
  #panel.rug(x = x[is.na(y)], y = y[is.na(x)])
}
)

# smoothing them produces reasonable lines
xyplot(fitted(model$gam) ~ Q95 |super.end.group, data = springP,
   lower = springP$lower,
   upper = springP$upper,
   subscripts = TRUE,
   panel = function(x,y, upper, lower, subscripts, ...){
  panel.xyplot(x,y, type="smooth")
  panel.xyplot(x[order(x)], upper[subscripts][order(x)], type = 
"smooth", lty=2, col="red")
  panel.xyplot(x[order(x)], lower[subscripts][order(x)], type = 
"smooth", lty=2, col="red")
  #panel.loess(x,y,...)
  #panel.rug(x = x[is.na(y)], y = y[is.na(x)])
}
)

# by newdata = ...
# take a cross-section of data - reduces the amount of data to be plotted
mx = aggregate(Q95 ~ super.end.group, spring, max, na.rm=T)
newlst <-
do.call(rbind,
lapply(1:6, function(j) expand.grid(Q95 = seq(0,mx[j,2], length = 50), 
super.end.group = LETTERS[j])
Year =
Hms_Rsctned =
...))   # fill in yourself
newd <- 

Re: [R] count number of stop words in R

2017-06-12 Thread Bert Gunter
I am unfamiliar with the tm package, but using basic regex tools, is
this what you want:

test <- "Mhm . Alright . There's um a young boy that's getting a
cookie jar . And it he's uh in bad shape because uh the thing is
falling over . And in the picture the mother is washing dishes and
doesn't see it . And so is the the water is overflowing in the sink .
And the dishes might get falled over if you don't fell fall over there
there if you don't get it . And it there it's a picture of a kitchen
window . And the curtains are very uh distinct . But the water is
still flowing ."

out <- strsplit(test, " ") ## creates a list whose only component is a
vector of the words

stopw <- c("a","the") ## or whatever they are

sum(grepl(paste(stopw,collapse="|"), out[[1]]))

## If you want to include ".", a regex special character, add:
sum(grepl(".",out[[1]],fixed=TRUE))


If this is all nonsense, just ignore -- and sorry I couldn't help.

-- Bert




Cheers,
Bert
Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Jun 12, 2017 at 8:23 AM, Elahe chalabi  wrote:
> Thanks for your reply. I know the command
> data <- tm_map(data, removeWords, stopwords("english"))
> removes English stop words, I don't know how should I count stop words of my 
> string:
>
>
> str="Mhm . Alright . There's um a young boy that's getting a cookie jar . And 
> it he's uh in bad shape because uh the thing is falling over . And in the 
> picture the mother is washing dishes and doesn't see it . And so is the the 
> water is overflowing in the sink . And the dishes might get falled over if 
> you don't fell fall over there there if you don't get it . And it there it's 
> a picture of a kitchen window . And the curtains are very uh distinct . But 
> the water is still flowing .
>
>
>
>
>
> On Monday, June 12, 2017 7:24 AM, Patrick Casimir  wrote:
>
>
>
> You can define stop words as below.
> data <- tm_map(data, removeWords, stopwords("english"))
>
>
> Patrick Casimir, PhD
> Health Analytics, Data Science, Big Data Expert & Independent Consultant
> C: 954.614.1178
>
> 
>
> From: R-help  on behalf of Bert Gunter 
> 
> Sent: Monday, June 12, 2017 10:12:33 AM
> To: Elahe chalabi
> Cc: R-help Mailing List
> Subject: Re: [R] count number of stop words in R
>
> You can use regular expressions.
>
> ?regex and/or the stringr package are good places to start.  Of
> course, you have to define "stop words."
>
>
> Cheers,
> Bert
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Mon, Jun 12, 2017 at 5:40 AM, Elahe chalabi via R-help
>  wrote:
>> Hi all,
>>
>> Is there a way in R to count the number of stop words (English) of a string 
>> using tm package?
>>
>> str="Mhm . Alright . There's um a young boy that's getting a cookie jar . 
>> And it he's uh in bad shape because uh the thing is falling over . And in 
>> the picture the mother is washing dishes and doesn't see it . And so is the 
>> the water is overflowing in the
> sink . And the dishes might get falled over if you don't fell fall over there 
> there if you don't get it . And it there it's a picture of a kitchen window . 
> And the curtains are very uh distinct . But the water is still flowing .
>>
>> 255 Levels: A boy's on the uh falling off the stool picking up cookies . The 
>> girl's reaching up for it . The girl the lady is is drying dishes . The 
>> water is uh running over uh from the sink into the floor . The window's 
>> opened . Dishes on the on the counter
> . She's outside ."
>>
>> Thanks for any help!
>> Elahe
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] count number of stop words in R

2017-06-12 Thread Florian Schwendinger
If you just want to count the stopwords you cloud do something like,

library(slam)
library(tm)

your_string <- "Mhm . Alright . There's um a young boy that's getting a cookie 
jar . And it he's uh in bad shape because uh the thing is falling over . And in 
the picture the mother is washing dishes and doesn't see it . And so is the the 
water is overflowing in the sink . And the dishes might get falled over if you 
don't fell fall over there there if you don't get it . And it there it's a 
picture of a kitchen window . And the curtains are very uh distinct . But the 
water is still flowing ."
corp <- Corpus(VectorSource(your_string))

stopwords("en")

cntrl <- list(tolower=TRUE, stopwords = NULL,
  removePunctuation = FALSE, removeNumbers = TRUE, 
  stemming = FALSE, wordLengths = c(0, Inf))


dtm <- DocumentTermMatrix(corp, cntrl)

col_sums(dtm[, which(colnames(dtm) %in% stopwords("en"))])



Best,
Florian
 

Gesendet: Montag, 12. Juni 2017 um 16:12 Uhr
Von: "Bert Gunter" 
An: "Elahe chalabi" 
Cc: "R-help Mailing List" 
Betreff: Re: [R] count number of stop words in R
You can use regular expressions.

?regex and/or the stringr package are good places to start. Of
course, you have to define "stop words."


Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Jun 12, 2017 at 5:40 AM, Elahe chalabi via R-help
 wrote:
> Hi all,
>
> Is there a way in R to count the number of stop words (English) of a string 
> using tm package?
>
> str="Mhm . Alright . There's um a young boy that's getting a cookie jar . And 
> it he's uh in bad shape because uh the thing is falling over . And in the 
> picture the mother is washing dishes and doesn't see it . And so is the the 
> water is overflowing in the sink . And the dishes might get falled over if 
> you don't fell fall over there there if you don't get it . And it there it's 
> a picture of a kitchen window . And the curtains are very uh distinct . But 
> the water is still flowing .
>
> 255 Levels: A boy's on the uh falling off the stool picking up cookies . The 
> girl's reaching up for it . The girl the lady is is drying dishes . The water 
> is uh running over uh from the sink into the floor . The window's opened . 
> Dishes on the on the counter . She's outside ."
>
> Thanks for any help!
> Elahe
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html[http://www.R-project.org/posting-guide.html]
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help[https://stat.ethz.ch/mailman/listinfo/r-help]
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html[http://www.R-project.org/posting-guide.html]
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] count number of stop words in R

2017-06-12 Thread Patrick Casimir
Or use the qdap package to perform any quantitative analysis of your string.

https://cran.r-project.org/web/packages/qdap/qdap.pdf

Package �qdap� - The Comprehensive R Archive 
Network
cran.r-project.org
Package �qdap� August 29, 2016 Type Package Title Bridging the Gap Between 
Qualitative Data and Quantitative Analysis Version 2.2.5 Date 2016-06-15





Patrick Casimir, PhD
Health Analytics, Data Science, Big Data Expert & Independent Consultant
C: 954.614.1178


From: Elahe chalabi 
Sent: Monday, June 12, 2017 11:42:43 AM
To: Patrick Casimir; Bert Gunter
Cc: R-help Mailing List
Subject: Re: [R] count number of stop words in R

Defining data as you mentioned in your respond causes the following error:


Error in UseMethod("tm_map", x) :
no applicable method for 'tm_map' applied to an object of class "character"

I can solve this error by using  Corpus(VectorSource(my string)) and the 
us[[elided Yahoo spam]]


On Monday, June 12, 2017 8:36 AM, Patrick Casimir  wrote:



define your string as whatever object you want:
data <- "Mhm . Alright . There's um a young boy that's getting a cookie jar . 
And it he's uh in bad shape because uh the thing is falling over . And in the 
picture the mother is washing dishes and doesn't see it . And so is the the 
water is overflowing in the sink . And the dishes might get falled over if you 
don't fell fall over there there if you don't get it . And it there it's a 
picture of a kitchen window . And the curtains are very uh distinct . But the 
water is still flowing."


Patrick Casimir, PhD
Health Analytics, Data Science, Big Data Expert & Independent Consultant
C: 954.614.1178




Sent: Monday, June 12, 2017 11:23:42 AM
To: Patrick Casimir; Bert Gunter
Cc: R-help Mailing List
Subject: Re: [R] count number of stop words in R

Thanks for your reply. I know the command
data <- tm_map(data, removeWords, stopwords("english"))
removes English stop words, I don't know how should I count stop words of my 
string:


str="Mhm . Alright . There's um a young boy that's getting a cookie jar . And 
it he's uh in bad shape because uh the thing is falling over . And in the 
picture the mother is washing dishes and doesn't see it . And so is the the 
water is overflowing in the sink
. And the dishes might get falled over if you don't fell fall over there there 
if you don't get it . And it there it's a picture of a kitchen window . And the 
curtains are very uh distinct . But the water is still flowing .





On Monday, June 12, 2017 7:24 AM, Patrick Casimir  wrote:



You can define stop words as below.
data <- tm_map(data, removeWords, stopwords("english"))


Patrick Casimir, PhD
Health Analytics, Data Science, Big Data Expert & Independent Consultant
C: 954.614.1178



From: R-help  on behalf of Bert Gunter 

Sent: Monday, June 12, 2017 10:12:33 AM
To: Elahe chalabi
Cc: R-help Mailing List
Subject: Re: [R] count number of stop words in R

You can use regular expressions.

?regex and/or the stringr package are good places to start.  Of
course, you have to define "stop words."


Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Jun 12, 2017 at 5:40 AM, Elahe chalabi via R-help
 wrote:
> Hi all,
>
> Is there a way in R to count the number of stop words (English) of a string 
> using tm package?
>
> str="Mhm . Alright . There's um a young boy that's getting a cookie jar . And 
> it he's uh in bad shape because uh the thing is falling over . And in the 
> picture the mother is washing dishes and doesn't see it . And so is the the 
> water is overflowing in the
sink . And the dishes might get falled over if you don't fell fall over there 
there if you don't get it . And it there it's a picture of a kitchen window . 
And the curtains are very uh distinct . But the water is still flowing .
>
> 255 Levels: A boy's on the uh falling off the stool picking up cookies . The 
> girl's reaching up for it . The girl the lady is is drying dishes . The water 
> is uh running over uh from the sink into the floor . The window's opened . 
> Dishes on the on the counter
. She's outside ."
>
[[elided Yahoo spam]]
> Elahe
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see

Re: [R] count number of stop words in R

2017-06-12 Thread Patrick Casimir
you can use

summary (my string)


Patrick Casimir, PhD
Health Analytics, Data Science, Big Data Expert & Independent Consultant
C: 954.614.1178


From: Elahe chalabi 
Sent: Monday, June 12, 2017 11:42:43 AM
To: Patrick Casimir; Bert Gunter
Cc: R-help Mailing List
Subject: Re: [R] count number of stop words in R

Defining data as you mentioned in your respond causes the following error:


Error in UseMethod("tm_map", x) :
no applicable method for 'tm_map' applied to an object of class "character"

I can solve this error by using  Corpus(VectorSource(my string)) and the 
us[[elided Yahoo spam]]


On Monday, June 12, 2017 8:36 AM, Patrick Casimir  wrote:



define your string as whatever object you want:
data <- "Mhm . Alright . There's um a young boy that's getting a cookie jar . 
And it he's uh in bad shape because uh the thing is falling over . And in the 
picture the mother is washing dishes and doesn't see it . And so is the the 
water is overflowing in the sink . And the dishes might get falled over if you 
don't fell fall over there there if you don't get it . And it there it's a 
picture of a kitchen window . And the curtains are very uh distinct . But the 
water is still flowing."


Patrick Casimir, PhD
Health Analytics, Data Science, Big Data Expert & Independent Consultant
C: 954.614.1178




Sent: Monday, June 12, 2017 11:23:42 AM
To: Patrick Casimir; Bert Gunter
Cc: R-help Mailing List
Subject: Re: [R] count number of stop words in R

Thanks for your reply. I know the command
data <- tm_map(data, removeWords, stopwords("english"))
removes English stop words, I don't know how should I count stop words of my 
string:


str="Mhm . Alright . There's um a young boy that's getting a cookie jar . And 
it he's uh in bad shape because uh the thing is falling over . And in the 
picture the mother is washing dishes and doesn't see it . And so is the the 
water is overflowing in the sink
. And the dishes might get falled over if you don't fell fall over there there 
if you don't get it . And it there it's a picture of a kitchen window . And the 
curtains are very uh distinct . But the water is still flowing .





On Monday, June 12, 2017 7:24 AM, Patrick Casimir  wrote:



You can define stop words as below.
data <- tm_map(data, removeWords, stopwords("english"))


Patrick Casimir, PhD
Health Analytics, Data Science, Big Data Expert & Independent Consultant
C: 954.614.1178



From: R-help  on behalf of Bert Gunter 

Sent: Monday, June 12, 2017 10:12:33 AM
To: Elahe chalabi
Cc: R-help Mailing List
Subject: Re: [R] count number of stop words in R

You can use regular expressions.

?regex and/or the stringr package are good places to start.  Of
course, you have to define "stop words."


Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Jun 12, 2017 at 5:40 AM, Elahe chalabi via R-help
 wrote:
> Hi all,
>
> Is there a way in R to count the number of stop words (English) of a string 
> using tm package?
>
> str="Mhm . Alright . There's um a young boy that's getting a cookie jar . And 
> it he's uh in bad shape because uh the thing is falling over . And in the 
> picture the mother is washing dishes and doesn't see it . And so is the the 
> water is overflowing in the
sink . And the dishes might get falled over if you don't fell fall over there 
there if you don't get it . And it there it's a picture of a kitchen window . 
And the curtains are very uh distinct . But the water is still flowing .
>
> 255 Levels: A boy's on the uh falling off the stool picking up cookies . The 
> girl's reaching up for it . The girl the lady is is drying dishes . The water 
> is uh running over uh from the sink into the floor . The window's opened . 
> Dishes on the on the counter
. She's outside ."
>
[[elided Yahoo spam]]
> Elahe
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do 

Re: [R] count number of stop words in R

2017-06-12 Thread Elahe chalabi via R-help
Defining data as you mentioned in your respond causes the following error:


Error in UseMethod("tm_map", x) : 
no applicable method for 'tm_map' applied to an object of class "character"

I can solve this error by using  Corpus(VectorSource(my string)) and the using 
your command but I cannot see the number of stop words in my string!


On Monday, June 12, 2017 8:36 AM, Patrick Casimir  wrote:



define your string as whatever object you want:
data <- "Mhm . Alright . There's um a young boy that's getting a cookie jar . 
And it he's uh in bad shape because uh the thing is falling over . And in the 
picture the mother is washing dishes and doesn't see it . And so is the the 
water is overflowing in the sink . And the dishes might get falled over if you 
don't fell fall over there there if you don't get it . And it there it's a 
picture of a kitchen window . And the curtains are very uh distinct . But the 
water is still flowing."


Patrick Casimir, PhD
Health Analytics, Data Science, Big Data Expert & Independent Consultant
C: 954.614.1178




Sent: Monday, June 12, 2017 11:23:42 AM
To: Patrick Casimir; Bert Gunter
Cc: R-help Mailing List
Subject: Re: [R] count number of stop words in R 
 
Thanks for your reply. I know the command  
data <- tm_map(data, removeWords, stopwords("english"))
removes English stop words, I don't know how should I count stop words of my 
string:


str="Mhm . Alright . There's um a young boy that's getting a cookie jar . And 
it he's uh in bad shape because uh the thing is falling over . And in the 
picture the mother is washing dishes and doesn't see it . And so is the the 
water is overflowing in the sink
. And the dishes might get falled over if you don't fell fall over there there 
if you don't get it . And it there it's a picture of a kitchen window . And the 
curtains are very uh distinct . But the water is still flowing .





On Monday, June 12, 2017 7:24 AM, Patrick Casimir  wrote:



You can define stop words as below.
data <- tm_map(data, removeWords, stopwords("english"))


Patrick Casimir, PhD
Health Analytics, Data Science, Big Data Expert & Independent Consultant
C: 954.614.1178



From: R-help  on behalf of Bert Gunter 

Sent: Monday, June 12, 2017 10:12:33 AM
To: Elahe chalabi
Cc: R-help Mailing List
Subject: Re: [R] count number of stop words in R 
 
You can use regular expressions.

?regex and/or the stringr package are good places to start.  Of
course, you have to define "stop words."


Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Jun 12, 2017 at 5:40 AM, Elahe chalabi via R-help
 wrote:
> Hi all,
>
> Is there a way in R to count the number of stop words (English) of a string 
> using tm package?
>
> str="Mhm . Alright . There's um a young boy that's getting a cookie jar . And 
> it he's uh in bad shape because uh the thing is falling over . And in the 
> picture the mother is washing dishes and doesn't see it . And so is the the 
> water is overflowing in the
sink . And the dishes might get falled over if you don't fell fall over there 
there if you don't get it . And it there it's a picture of a kitchen window . 
And the curtains are very uh distinct . But the water is still flowing .
>
> 255 Levels: A boy's on the uh falling off the stool picking up cookies . The 
> girl's reaching up for it . The girl the lady is is drying dishes . The water 
> is uh running over uh from the sink into the floor . The window's opened . 
> Dishes on the on the counter
. She's outside ."
>
[[elided Yahoo spam]]
> Elahe
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] count number of stop words in R

2017-06-12 Thread Patrick Casimir
define your string as whatever object you want:

data <- "Mhm . Alright . There's um a young boy that's getting a cookie jar . 
And it he's uh in bad shape because uh the thing is falling over . And in the 
picture the mother is washing dishes and doesn't see it . And so is the the 
water is overflowing in the sink . And the dishes might get falled over if you 
don't fell fall over there there if you don't get it . And it there it's a 
picture of a kitchen window . And the curtains are very uh distinct . But the 
water is still flowing."



Patrick Casimir, PhD
Health Analytics, Data Science, Big Data Expert & Independent Consultant
C: 954.614.1178


From: Elahe chalabi 
Sent: Monday, June 12, 2017 11:23:42 AM
To: Patrick Casimir; Bert Gunter
Cc: R-help Mailing List
Subject: Re: [R] count number of stop words in R

Thanks for your reply. I know the command
data <- tm_map(data, removeWords, stopwords("english"))
removes English stop words, I don't know how should I count stop words of my 
string:


str="Mhm . Alright . There's um a young boy that's getting a cookie jar . And 
it he's uh in bad shape because uh the thing is falling over . And in the 
picture the mother is washing dishes and doesn't see it . And so is the the 
water is overflowing in the sink . And the dishes might get falled over if you 
don't fell fall over there there if you don't get it . And it there it's a 
picture of a kitchen window . And the curtains are very uh distinct . But the 
water is still flowing .





On Monday, June 12, 2017 7:24 AM, Patrick Casimir  wrote:



You can define stop words as below.
data <- tm_map(data, removeWords, stopwords("english"))


Patrick Casimir, PhD
Health Analytics, Data Science, Big Data Expert & Independent Consultant
C: 954.614.1178



From: R-help  on behalf of Bert Gunter 

Sent: Monday, June 12, 2017 10:12:33 AM
To: Elahe chalabi
Cc: R-help Mailing List
Subject: Re: [R] count number of stop words in R

You can use regular expressions.

?regex and/or the stringr package are good places to start.  Of
course, you have to define "stop words."


Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Jun 12, 2017 at 5:40 AM, Elahe chalabi via R-help
 wrote:
> Hi all,
>
> Is there a way in R to count the number of stop words (English) of a string 
> using tm package?
>
> str="Mhm . Alright . There's um a young boy that's getting a cookie jar . And 
> it he's uh in bad shape because uh the thing is falling over . And in the 
> picture the mother is washing dishes and doesn't see it . And so is the the 
> water is overflowing in the
sink . And the dishes might get falled over if you don't fell fall over there 
there if you don't get it . And it there it's a picture of a kitchen window . 
And the curtains are very uh distinct . But the water is still flowing .
>
> 255 Levels: A boy's on the uh falling off the stool picking up cookies . The 
> girl's reaching up for it . The girl the lady is is drying dishes . The water 
> is uh running over uh from the sink into the floor . The window's opened . 
> Dishes on the on the counter
. She's outside ."
>
[[elided Yahoo spam]]
> Elahe
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] count number of stop words in R

2017-06-12 Thread Elahe chalabi via R-help
Thanks for your reply. I know the command  
data <- tm_map(data, removeWords, stopwords("english"))
removes English stop words, I don't know how should I count stop words of my 
string:


str="Mhm . Alright . There's um a young boy that's getting a cookie jar . And 
it he's uh in bad shape because uh the thing is falling over . And in the 
picture the mother is washing dishes and doesn't see it . And so is the the 
water is overflowing in the sink . And the dishes might get falled over if you 
don't fell fall over there there if you don't get it . And it there it's a 
picture of a kitchen window . And the curtains are very uh distinct . But the 
water is still flowing .





On Monday, June 12, 2017 7:24 AM, Patrick Casimir  wrote:



You can define stop words as below.
data <- tm_map(data, removeWords, stopwords("english"))


Patrick Casimir, PhD
Health Analytics, Data Science, Big Data Expert & Independent Consultant
C: 954.614.1178



From: R-help  on behalf of Bert Gunter 

Sent: Monday, June 12, 2017 10:12:33 AM
To: Elahe chalabi
Cc: R-help Mailing List
Subject: Re: [R] count number of stop words in R 
 
You can use regular expressions.

?regex and/or the stringr package are good places to start.  Of
course, you have to define "stop words."


Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Jun 12, 2017 at 5:40 AM, Elahe chalabi via R-help
 wrote:
> Hi all,
>
> Is there a way in R to count the number of stop words (English) of a string 
> using tm package?
>
> str="Mhm . Alright . There's um a young boy that's getting a cookie jar . And 
> it he's uh in bad shape because uh the thing is falling over . And in the 
> picture the mother is washing dishes and doesn't see it . And so is the the 
> water is overflowing in the
sink . And the dishes might get falled over if you don't fell fall over there 
there if you don't get it . And it there it's a picture of a kitchen window . 
And the curtains are very uh distinct . But the water is still flowing .
>
> 255 Levels: A boy's on the uh falling off the stool picking up cookies . The 
> girl's reaching up for it . The girl the lady is is drying dishes . The water 
> is uh running over uh from the sink into the floor . The window's opened . 
> Dishes on the on the counter
. She's outside ."
>
[[elided Yahoo spam]]
> Elahe
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] count number of stop words in R

2017-06-12 Thread Patrick Casimir
You can define stop words as below.

data <- tm_map(data, removeWords, stopwords("english"))



Patrick Casimir, PhD
Health Analytics, Data Science, Big Data Expert & Independent Consultant
C: 954.614.1178


From: R-help  on behalf of Bert Gunter 

Sent: Monday, June 12, 2017 10:12:33 AM
To: Elahe chalabi
Cc: R-help Mailing List
Subject: Re: [R] count number of stop words in R

You can use regular expressions.

?regex and/or the stringr package are good places to start.  Of
course, you have to define "stop words."


Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Jun 12, 2017 at 5:40 AM, Elahe chalabi via R-help
 wrote:
> Hi all,
>
> Is there a way in R to count the number of stop words (English) of a string 
> using tm package?
>
> str="Mhm . Alright . There's um a young boy that's getting a cookie jar . And 
> it he's uh in bad shape because uh the thing is falling over . And in the 
> picture the mother is washing dishes and doesn't see it . And so is the the 
> water is overflowing in the sink . And the dishes might get falled over if 
> you don't fell fall over there there if you don't get it . And it there it's 
> a picture of a kitchen window . And the curtains are very uh distinct . But 
> the water is still flowing .
>
> 255 Levels: A boy's on the uh falling off the stool picking up cookies . The 
> girl's reaching up for it . The girl the lady is is drying dishes . The water 
> is uh running over uh from the sink into the floor . The window's opened . 
> Dishes on the on the counter . She's outside ."
>
> Thanks for any help!
> Elahe
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] count number of stop words in R

2017-06-12 Thread Bert Gunter
You can use regular expressions.

?regex and/or the stringr package are good places to start.  Of
course, you have to define "stop words."


Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Jun 12, 2017 at 5:40 AM, Elahe chalabi via R-help
 wrote:
> Hi all,
>
> Is there a way in R to count the number of stop words (English) of a string 
> using tm package?
>
> str="Mhm . Alright . There's um a young boy that's getting a cookie jar . And 
> it he's uh in bad shape because uh the thing is falling over . And in the 
> picture the mother is washing dishes and doesn't see it . And so is the the 
> water is overflowing in the sink . And the dishes might get falled over if 
> you don't fell fall over there there if you don't get it . And it there it's 
> a picture of a kitchen window . And the curtains are very uh distinct . But 
> the water is still flowing .
>
> 255 Levels: A boy's on the uh falling off the stool picking up cookies . The 
> girl's reaching up for it . The girl the lady is is drying dishes . The water 
> is uh running over uh from the sink into the floor . The window's opened . 
> Dishes on the on the counter . She's outside ."
>
> Thanks for any help!
> Elahe
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Keep only those values in a row in a data frame which occur only once.

2017-06-12 Thread S Ellison
> I have a file data.txt as follows:
> 
> Name_1,A,B,C
> Name_2,E,F
> Name_3,I,J,I,K,L,M
> 
> My query is how can I keep only the unique elements in each row? For
> example: I want the row 3 to be Name_3,I,J,K,L,M
> 
> Please note I don't want the 2nd I to appear.
> 
> How can I do this?
Use unique() on each row and pad with NA?

Example:
uniq10 <- function(x, L=10) {
u <- unique(x)
c(u, rep(NA, L-length(u)) )
}

as.data.frame(  t( apply(tmp, 1, uniq10)  )  )

assuming tmp is the name of your initial data frame.

S Ellison




***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R-es] QUitar bucles for

2017-06-12 Thread Javier Marcuzzi
Estimado Jesús Para Fernández

Si y No. En R antiguo, for no estaba vectorizado, o dicho de otra forma, R no 
esta vectorizado, para tener un rendimiento mayor hay formas de escribir donde 
aumenta el rendimiento, por otro lado aparecen funciones que colaboran para 
ordenar o trabajar con datos, como las que usted nombra y algunas otras.

Todas estas dentro de su código tienen algún ciclo, un bucle en algún lenguaje 
seguro que tienen, el problema esta en la facilidad de escritura y gustos para 
escribir en R.

Por otro lado, las versiones actuales de R mejoraron esa diferencia respecto a 
si esta o no vectorizado, incluso puede usar compile(), por lo cuál la 
diferencia de rendimiento hoy podría ser una anécdota.

Javier Rubén Marcuzzi

De: Jesús Para Fernández
Enviado: lunes, 12 de junio de 2017 10:38
Para: r-help-es@r-project.org
Asunto: [R-es] QUitar bucles for

Es siempre posible sustituir un bucle for por un lapply o mapply=???


Gracias

JEs�s

[[alternative HTML version deleted]]



[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R] Problem related to rowSums

2017-06-12 Thread PIKAL Petr
Hi

Not sure of your intention, do you want count how many rows have zeroes in all 
columns?

In that case something like

sum(rowSums(dat == 0) == ncol(dat))

should do the trick.

If it is not an answer for your problem, post some toy data and desired result.

Regards
Petr


> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Yogesh
> Gupta
> Sent: Wednesday, June 7, 2017 11:09 AM
> To: r-help@r-project.org
> Subject: [R] Problem related to rowSums
>
> Hi...
>
> I have a dataframe with n columns and n rows. I need to find how many rows
> contains zero raw read count across all column.
>
> Thanks
>
> --
> *Yogesh Gupta*
> *Postdoctoral Researcher*
> *Department of Biological Science*
> *Seoul National University*
> *Seoul, South Korea*
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the person represented by the 
recipient, or the existence of such authorization is known to the recipient of 
the person represented by the recipient.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R-es] Bucle for que se salte los errores

2017-06-12 Thread Javier Marcuzzi
Estimado Jesús Para Fernández

Pero no es lo mismo, usted pidió para cuándo i vale 0, el tryCatch es para 
todos los casos en donde no se puede porque hay un error, justo coloco en el 
buscador la definición para compartirla y encuentro un ejemplo muy apropiado.

# tryCatch.Rscript -- experiments with tryCatch
 
# Get any arguments
arguments <- commandArgs(trailingOnly=TRUE)
a <- arguments[1]
 
# Define a division function that can issue warnings and errors
myDivide <- function(d, a) {
  if (a == 'warning') {
    return_value <- 'myDivide warning result'
warning("myDivide warning message")
  } else if (a == 'error') {
    return_value <- 'myDivide error result'
stop("myDivide error message")
  } else {
    return_value = d / as.numeric(a)
  }
  return(return_value)
}
 
# Evalute the desired series of expressions inside of tryCatch
result <- tryCatch({
 
  b <- 2
  c <- b^2
  d <- c+2
  if (a == 'suppress-warnings') {
    e <- suppressWarnings(myDivide(d,a))
  } else {
    e <- myDivide(d,a) # 6/a
  }
  f <- e + 100
 
}, warning = function(war) {
 
  # warning handler picks up where error was generated
  print(paste("MY_WARNING:  ",war))
  b <- "changing 'b' inside the warning handler has no effect"
  e <- myDivide(d,0.1) # =60
  f <- e + 100
  return(f)
 
}, error = function(err) {
 
  # error handler picks up where error was generated
  print(paste("MY_ERROR:  ",err))
  b <- "changing 'b' inside the error handler has no effect"
  e <- myDivide(d,0.01) # =600
  f <- e + 100
  return(f)
 
}, finally = {
 
  print(paste("a =",a))
  print(paste("b =",b))
  print(paste("c =",c))
  print(paste("d =",d))
  # NOTE:  Finally is evaluated in the context of of the inital
  # NOTE:  tryCatch block and 'e' will not exist if a warning
  # NOTE:  or error occurred.
  #print(paste("e =",e))
 
}) # END tryCatch
 
print(paste("result =",result))

Javier Rubén Marcuzzi

De: Jesús Para Fernández
Enviado: lunes, 12 de junio de 2017 9:57
Para: Javier Marcuzzi; Xavi tibau alberdi; guillermo.vi...@uv.es
CC: Lista R
Asunto: Re: [R-es] Bucle for que se salte los errores

He encontrado la respuesta. EL ejemplo que puse era trivial, ya que es obvio 
que if(i ==0) entonces next, pero me referia a sin saber si va a ser error el 
modelo o no. 

Para esto he encontrado la solución 
for(i in -3:3){
tryCatch({
  z<-1/i
>   z<-z*z
>   modelo<-lm(z~1)

}, error=function(e){print("es un error"})

}


Gracias de todas maneras!
Jesús


De: R-help-es  en nombre de Javier Marcuzzi 

Enviado: lunes, 12 de junio de 2017 14:48
Para: Xavi tibau alberdi; guillermo.vi...@uv.es
Cc: Lista R
Asunto: Re: [R-es] Bucle for que se salte los errores 
 
Case también podría ir, en realidad cualquier función de condicional, hay algo 
de gusto personal también (yo prefiero if).

Javier Rubén Marcuzzi

De: Xavi tibau alberdi
Enviado: lunes, 12 de junio de 2017 9:46
Para: guillermo.vi...@uv.es
CC: Lista R
Asunto: Re: [R-es] Bucle for que se salte los errores

Otra opcio es  no incluir en 0

For (i in c(-2,-1,1,2)


El 12 jun. 2017 14:43,  escribió:

Hola,

Creo que sería añadir if(i == 0) next

Saludos,

Guillermo

> Buenas, �como puedo hacer que el bucle for se salte el error que salta
cuando i<-0 en el codigo que paso??
>
>
>
> count <- 0
> for(i in -2:2){
>   z<-1/i
>   z<-z*z
>   modelo<-lm(z~1)
> }
>
>
> Gracias
>
>
>
>
>
>   [[alternative HTML version deleted]]
>
>

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es 
Página de Información de R-help-es
stat.ethz.ch
Esta es una lista de correo para solicitar ayuda sobre R en español y se 
entiende como un complemento social a la documentación, libros, etc. 
disponibles sobre R ...


    [[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es 
Página de Información de R-help-es
stat.ethz.ch
Esta es una lista de correo para solicitar ayuda sobre R en español y se 
entiende como un complemento social a la documentación, libros, etc. 
disponibles sobre R ...



    [[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es
Página de Información de R-help-es
stat.ethz.ch
Esta es una lista de correo para solicitar ayuda sobre R en español y se 
entiende como un complemento social a la documentación, libros, etc. 
disponibles sobre R ...

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R-es] Bucle for que se salte los errores

2017-06-12 Thread Jesús Para Fernández
He encontrado la respuesta. EL ejemplo que puse era trivial, ya que es obvio 
que if(i ==0) entonces next, pero me referia a sin saber si va a ser error el 
modelo o no.

Para esto he encontrado la solución

for(i in -3:3){

tryCatch({

  z<-1/i
>   z<-z*z
>   modelo<-lm(z~1)


}, error=function(e){print("es un error"})


}



Gracias de todas maneras!
Jesús



De: R-help-es  en nombre de Javier Marcuzzi 

Enviado: lunes, 12 de junio de 2017 14:48
Para: Xavi tibau alberdi; guillermo.vi...@uv.es
Cc: Lista R
Asunto: Re: [R-es] Bucle for que se salte los errores

Case también podría ir, en realidad cualquier función de condicional, hay algo 
de gusto personal también (yo prefiero if).

Javier Rubén Marcuzzi

De: Xavi tibau alberdi
Enviado: lunes, 12 de junio de 2017 9:46
Para: guillermo.vi...@uv.es
CC: Lista R
Asunto: Re: [R-es] Bucle for que se salte los errores

Otra opcio es  no incluir en 0

For (i in c(-2,-1,1,2)


El 12 jun. 2017 14:43,  escribió:

Hola,

Creo que sería añadir if(i == 0) next

Saludos,

Guillermo

> Buenas, �como puedo hacer que el bucle for se salte el error que salta
cuando i<-0 en el codigo que paso??
>
>
>
> count <- 0
> for(i in -2:2){
>   z<-1/i
>   z<-z*z
>   modelo<-lm(z~1)
> }
>
>
> Gracias
>
>
>
>
>
>   [[alternative HTML version deleted]]
>
>

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es
Página de Información de 
R-help-es
stat.ethz.ch
Esta es una lista de correo para solicitar ayuda sobre R en español y se 
entiende como un complemento social a la documentación, libros, etc. 
disponibles sobre R ...




[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es
Página de Información de 
R-help-es
stat.ethz.ch
Esta es una lista de correo para solicitar ayuda sobre R en español y se 
entiende como un complemento social a la documentación, libros, etc. 
disponibles sobre R ...





[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es
Página de Información de 
R-help-es
stat.ethz.ch
Esta es una lista de correo para solicitar ayuda sobre R en español y se 
entiende como un complemento social a la documentación, libros, etc. 
disponibles sobre R ...



[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R-es] Bucle for que se salte los errores

2017-06-12 Thread Javier Marcuzzi
Case también podría ir, en realidad cualquier función de condicional, hay algo 
de gusto personal también (yo prefiero if).

Javier Rubén Marcuzzi

De: Xavi tibau alberdi
Enviado: lunes, 12 de junio de 2017 9:46
Para: guillermo.vi...@uv.es
CC: Lista R
Asunto: Re: [R-es] Bucle for que se salte los errores

Otra opcio es  no incluir en 0

For (i in c(-2,-1,1,2)


El 12 jun. 2017 14:43,  escribió:

Hola,

Creo que sería añadir if(i == 0) next

Saludos,

Guillermo

> Buenas, �como puedo hacer que el bucle for se salte el error que salta
cuando i<-0 en el codigo que paso??
>
>
>
> count <- 0
> for(i in -2:2){
>   z<-1/i
>   z<-z*z
>   modelo<-lm(z~1)
> }
>
>
> Gracias
>
>
>
>
>
>   [[alternative HTML version deleted]]
>
>

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R-es] Bucle for que se salte los errores

2017-06-12 Thread Xavi tibau alberdi
Otra opcio es  no incluir en 0

For (i in c(-2,-1,1,2)


El 12 jun. 2017 14:43,  escribió:

Hola,

Creo que sería añadir if(i == 0) next

Saludos,

Guillermo

> Buenas, �como puedo hacer que el bucle for se salte el error que salta
cuando i<-0 en el codigo que paso??
>
>
>
> count <- 0
> for(i in -2:2){
>   z<-1/i
>   z<-z*z
>   modelo<-lm(z~1)
> }
>
>
> Gracias
>
>
>
>
>
>   [[alternative HTML version deleted]]
>
>

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R-es] Bucle for que se salte los errores

2017-06-12 Thread Javier Marcuzzi
Estimado Jesús Para Fernández

Usando un if dentro de for

Algo como 
If i<- 0  no hacer , else hacer

Javier Rubén Marcuzzi

De: Jesús Para Fernández
Enviado: lunes, 12 de junio de 2017 9:29
Para: r-help-es@r-project.org
Asunto: [R-es] Bucle for que se salte los errores

Buenas, �como puedo hacer que el bucle for se salte el error que salta cuando 
i<-0 en el codigo que paso??



count <- 0
for(i in -2:2){
  z<-1/i
  z<-z*z
  modelo<-lm(z~1)
}


Gracias





[[alternative HTML version deleted]]



[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

[R] count number of stop words in R

2017-06-12 Thread Elahe chalabi via R-help
Hi all,

Is there a way in R to count the number of stop words (English) of a string 
using tm package?

str="Mhm . Alright . There's um a young boy that's getting a cookie jar . And 
it he's uh in bad shape because uh the thing is falling over . And in the 
picture the mother is washing dishes and doesn't see it . And so is the the 
water is overflowing in the sink . And the dishes might get falled over if you 
don't fell fall over there there if you don't get it . And it there it's a 
picture of a kitchen window . And the curtains are very uh distinct . But the 
water is still flowing . 

255 Levels: A boy's on the uh falling off the stool picking up cookies . The 
girl's reaching up for it . The girl the lady is is drying dishes . The water 
is uh running over uh from the sink into the floor . The window's opened . 
Dishes on the on the counter . She's outside ."

Thanks for any help!
Elahe

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R-es] OPINIONES comparacion personal de R en linux y windows

2017-06-12 Thread Javier Marcuzzi
Buenos días a todos

Estimado Eric

R tiene dos partes, por un lado el que realiza cálculos y por el otro la forma 
de poder enviar lo que se debe hacer, esto es a partir de un archivo, 
escribiendo en una terminal, usando rstudio, rkward, entre otros, yo no 
recuerdo cuál fue la versión de R que use primero, si puedo decir que era en un 
pentium 866 con suse 8,6 y R era 1 y algo, no llegaba a la versión 2 (recuerdo 
eso porque yo tenía una imac y mi profesor en genética me enseñaba fortran y 
era menos dinero comprar otra computadora con Linux que un compilador), y en 
ese entonces había ventanas que me permitían arrastrar el código de R 
directamente a la terminal y se ejecutaba, otras que no, luego con otra 
computadora apple con unos años más de desarrollo me resultaba más cómodo el R 
en mac. En este sentido hay mucho de gusto personal y forma de trabajo, hoy en 
día estoy probando R en visual studio y en algunos aspectos me resulta más 
práctico que rstudio.

Pero por el otro lado está el R que calcula, al respecto me refería a realizar 
algo simple, como usar system.time().

No realizar comparaciones midiendo variables informáticas, algo simple como, en 
la misma computadora instalar R en Windows y Linux, correr el mismo código R, y 
medir cuánto tiempo demora. Yo en mi computadora hoy en día no puedo hacerlo 
porque no es posible instalar Linux (es una sin DVD, todo en particiones de 
disco según configuro el fabricante, si toco el arranque no tengo ni idea como 
se soluciona un problema).

Javier Rubén Marcuzzi

De: eric
Enviado: lunes, 12 de junio de 2017 8:32
Para: Javier Valdes Cantallopts (DGA); Javier Nieto; Javier Marcuzzi; Carlos 
Ortega (c...@qualityexcellence.es)
CC: r-help-es@r-project.org
Asunto: Re: [R-es] OPINIONES comparacion personal de R en linux y windows

Hola Javier, he usado R principalmente en Linux, y principalmente en debian, 
aunque he tenido que usarlo tambien sobre windows y sobre otras distribuciones 
de Linux. La usabilidad a traves de todos ellos es basicamente la misma para 
mi, pues uso rkward que se puede instalar en todos los OS que mencione. Quiza 
la mayor diferencia que he encontrado, tiene que ver con la velocidad cuando 
usas scripts complejos con bbdd grandes, en linux funciona mucho mas rapido. 
Pero creo que es, principalmente, porque linux en general funciona mas rapido, 
ya que no se llena de "XXXware" que se inicia en el arranque y estan ahi usando 
la RAM y el procesador cuando nadie se los pide. En cualquier caso, es una 
impresion subjetiva, aunque diria que bastante ajustada a la realidad pues es 
muy evidente. He hecho muy pocos benchmarks, y en general han sido para 
comparar entre librerias que hacen lo mismo dentro de R, mas que para comparar 
el desempeño de las mismas librerias en diferentes SO.

Espero haberte dado una idea.

Si se animan podriamos organizar un benchmarking masivo para comparar las 
mismas configuraciones de R en diferentes maquinas y SO, o algo asi.

Saludos, Eric.





On 06/07/2017 02:07 PM, Javier Valdes Cantallopts (DGA) wrote:
Buena la idea de hacer una especie de diagnóstico entre las distribuciones, a 
modo de información entre los que contribuimos de alguna manera al foro.
En mi caso, en ubuntu y fedora anda muy bien.
Podría probar con Opensuse..
 

 
De: Javier Nieto [mailto:mac_j...@hotmail.com] 
Enviado el: miércoles, 07 de junio de 2017 12:42
Para: Javier Marcuzzi; Javier Valdes Cantallopts (DGA); Carlos Ortega 
(c...@qualityexcellence.es)
CC: r-help-es@r-project.org
Asunto: Re: OPINIONES comparacion personal de R en linux y windows
 
Me parece que R funciona mejor en Linux que en Windows, en mac ni idea. Un buen 
ejercicio sería hacer lo que plantea Marcuzzi Linux con Linux, en lo personal 
lo he probrado en Ubuntu, Centos, Oracle Linux y Fedora y no he sentido 
diferencias significativas, tal vez porque han sido tareas diferentes. Sería 
que bueno hacer un benchmark  y ver que resultados salen o si alguien ya lo ha 
realizado tal vez pueda compartirlo.
 
 
Saludos

De: R-help-es  en nombre de Javier Marcuzzi 

Enviado: miércoles, 7 de junio de 2017 11:27:22 a. m.
Para: Javier Valdes Cantallopts (DGA); Carlos Ortega (c...@qualityexcellence.es)
CC: r-help-es@r-project.org
Asunto: Re: [R-es] OPINIONES comparacion personal de R en linux y windows 
 
Estimado Javier Valdes Cantallopts
 
Hace mucho que no uso R en Linux ni en mac, como experiencia de usuario Windows 
no es tan cómodo, aunque realice lo mismo, sin embargo es algo muy personal que 
tiene más que ver con la interfaz gráfica y su funcionamiento, aunque R en 
Ubuntu me parecía desafortunado al lado de R en SUSE.
 
Creo que debe hacer diferencias en la compilación (o el compilador). Pero si 
usted puede intente realizar el mismo trabajo con (no recuerdo justo el 
comando) para marcar el tiempo que demora.
 
Javier Rubén Marcuzzi
 
De: Javier Valdes Cantallopts (DGA)
Enviado: miércoles, 7 de 

Re: [R-es] Bucle for que se salte los errores

2017-06-12 Thread Guillermo.Vinue
Hola,

Creo que sería añadir if(i == 0) next

Saludos,

Guillermo 

> Buenas, �como puedo hacer que el bucle for se salte el error que salta cuando 
> i<-0 en el codigo que paso??
> 
> 
> 
> count <- 0
> for(i in -2:2){
>   z<-1/i
>   z<-z*z
>   modelo<-lm(z~1)
> }
> 
> 
> Gracias
> 
> 
> 
> 
> 
>   [[alternative HTML version deleted]]
> 
> 

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R-es] OPINIONES comparacion personal de R en linux y windows

2017-06-12 Thread eric

  
  
Hola Javier, he usado R principalmente en Linux, y principalmente
  en debian, aunque he tenido que usarlo tambien sobre windows y
  sobre otras distribuciones de Linux. La usabilidad a traves de
  todos ellos es basicamente la misma para mi, pues uso rkward que
  se puede instalar en todos los OS que mencione. Quiza la mayor
  diferencia que he encontrado, tiene que ver con la velocidad
  cuando usas scripts complejos con bbdd grandes, en linux funciona
  mucho mas rapido. Pero creo que es, principalmente, porque linux
  en general funciona mas rapido, ya que no se llena de "XXXware"
  que se inicia en el arranque y estan ahi usando la RAM y el
  procesador cuando nadie se los pide. En cualquier caso, es una
  impresion subjetiva, aunque diria que bastante ajustada a la
  realidad pues es muy evidente. He hecho muy pocos benchmarks, y en
  general han sido para comparar entre librerias que hacen lo mismo
  dentro de R, mas que para comparar el desempeño de las mismas
  librerias en diferentes SO.


Espero haberte dado una idea.


Si se animan podriamos organizar un benchmarking masivo para
  comparar las mismas configuraciones de R en diferentes maquinas y
  SO, o algo asi.


Saludos, Eric.










On 06/07/2017 02:07 PM, Javier Valdes
  Cantallopts (DGA) wrote:


  
  
  
  
  
Buena la idea
de hacer una especie de diagnóstico entre las
distribuciones, a modo de información entre los que
contribuimos de alguna manera al foro.
En mi caso, en
ubuntu y fedora anda muy bien.
Podría probar
con Opensuse..
 

  

 

  
De: Javier Nieto [mailto:mac_j...@hotmail.com]

Enviado el: miércoles, 07 de junio de 2017 12:42
Para: Javier Marcuzzi; Javier Valdes Cantallopts
(DGA); Carlos Ortega (c...@qualityexcellence.es)
CC: r-help-es@r-project.org
Asunto: Re: OPINIONES comparacion personal de R
en linux y windows
  

 

  Me parece que R funciona mejor en Linux que en
  Windows, en mac ni idea. Un buen ejercicio sería hacer lo
  que plantea Marcuzzi Linux con Linux, en lo personal lo he
  probrado en Ubuntu, Centos, Oracle Linux y Fedora y no he
  sentido diferencias significativas, tal vez porque han
  sido tareas diferentes. Sería que bueno hacer un
  benchmark  y ver que resultados salen o si alguien ya lo
  ha realizado tal vez pueda compartirlo.
   
   
  Saludos



  

  De: R-help-es
   en nombre de
  Javier Marcuzzi 
  Enviado: miércoles, 7 de junio de 2017 11:27:22 a.
  m.
  Para: Javier Valdes Cantallopts (DGA); Carlos
  Ortega (c...@qualityexcellence.es)
  CC: r-help-es@r-project.org
  Asunto: Re: [R-es] OPINIONES comparacion personal
  de R en linux y windows
  
  
 
  


  Estimado Javier Valdes
  Cantallopts
   
  Hace mucho que no uso R
  en Linux ni en mac, como experiencia de usuario Windows no
  es tan cómodo, aunque realice lo mismo, sin embargo es
  algo muy personal que tiene más que ver con la interfaz
  gráfica y su funcionamiento, aunque R en Ubuntu me parecía
  desafortunado al lado de R en SUSE.
   
  Creo que debe hacer
  diferencias en la compilación (o el compilador). Pero si
  usted puede intente realizar el mismo trabajo con (no
  recuerdo justo el comando) para marcar el tiempo que
  demora.
   
  Javier Rubén Marcuzzi
   
  
De: Javier Valdes
  Cantallopts (DGA)
Enviado: miércoles, 7 de junio de 2017 11:33
Para: Carlos Ortega
  (c...@qualityexcellence.es)
CC: r-help-es@r-project.org
Asunto: [R-es] OPINIONES comparacion personal de
R en linux y windows
  
   
  Hola
  estimados.
  Les
  quería plantear un tema que tiene que ver con las
  plataformas en donde hacemos correr nuestro R.
  En
  mi caso, tengo instalado R en mi oficina(Windows) y en mi
  casa(Linux) y la verdad, después de probar algunas

Re: [R-es] Agregar a un data.frame de manera automatica

2017-06-12 Thread Jesús Para Fernández
Me autocontesto, hacinedolo de la siguiente manera:


for(i in 1:240) {

  df[paste("inicio.refri", i, sep = 
".")]<-datos[which.max(datos[,109+i]),"LogDateTime"]

}



No hace falta usar el assing ni similares. Para nota, ¿se podria hacer con un 
lapply o similares?? y evitar usar el for?

Gracias

Jesús


De: R-help-es  en nombre de Jesús Para 
Fernández 
Enviado: lunes, 12 de junio de 2017 11:58
Para: r-help-es@r-project.org
Asunto: [R-es] Agregar a un data.frame de manera automatica

Buenas,


Tengo un monton de variables que quiero meter en un data.frame.


Las variables las he ido extrayendo de la siguiente manera

for(i in 1:240) {
  #saco el inicio de cada refrigeracion
  aux1 <- paste("inicio.refri", i, sep = ".")
  assign(aux1,datos[which.max(datos[,109+i]),"LogDateTime"])

}


Y quiero buscar una funcion que me permita meter esas 240 inicio.refri1, 
inicio.refri.240, en un data.frame como columnas, no como filas.

�Como puedo hacerlo de manera autom�tica?


Gracias!!!
Jes�s

[[alternative HTML version deleted]]


[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R] Memory leak in nleqslv()

2017-06-12 Thread Ismail SEZEN

> On 12 Jun 2017, at 00:16, Andrew Leach  wrote:
> 
> Hello all,
> 
> I am relatively new to R, but enjoying it very much.  I am hoping that
> someone on this list can help me with an issue I am having.
> 
> I am having issues with iterations over nleqslv, in that the solver
> does not appear to clean up memory used in previous iterations. I
> believe I've isolated the/my issue in a small sample of code:
> 
> library(nleqslv)
> 
> cons_ext_test <- function(x){
> rows_x <- length(x)/2
> x_1 <- x[1:rows_x]
> x_2 <- x[(rows_x+1):(rows_x*2)]
> eq1<- x_1-100
> eq2<-x_2*10-40
> return(c(eq1,eq2))
> }
> 
> model_test <- function()
> {
> reserves<-(c(0:200)/200)^(2)*2000
> lambda <- numeric(NROW(reserves))+5
> res_ext <- pmin((reserves*.5),5)
> x_test <- c(res_ext,lambda)
> #print(x_test)
> for(test_iter in c(1:1000))
>   nleqslv(x_test,cons_ext_test,jacobian=NULL)
> i<- sort( sapply(ls(),function(x){object.size(get(x))}))
> print(i[(NROW(i)-5):NROW(i)])
> }
> 
> model_test()
> 
> When I run this over 1000 iterations, memory use ramps up to over 2.4 GB
> 
> While running it with 10 iterations uses far less memory, only 95MB:
> 
> Running it once has my rsession with 62Mb of use, so growth in memory
> allocation scales with iterations.
> 
> Even after 1000 iterations, with 2+ GB of memory used by the R
> session, no large-sized objects are listed, although mem_use() shows
> 2+ GB of memory used.
> 
> test_iterlambda   res_ext  reservesx_test
>   48  1648 1648  1648  3256
> 
> I've replicated this on OS-X and in Windows both on a desktop and a
> Surface Pro, however colleagues have run this on their machines and
> not found the same result.  gc() does not rectify the issue, although
> re-starting R does.
> 
> Any help would be much appreciated.
> 
> AJL
> 


Hello Andrew,

I could replicated same result. I think it’s time to send a bug report to 
author (Berend Hasselman ).

> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.5

Matrix products: default
BLAS: 
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: 
/Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics  grDevices datasets  utils methods   base 

other attached packages:
[1] nleqslv_3.3

loaded via a namespace (and not attached):
[1] compiler_3.4.0 tools_3.4.0 
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] plspm package error in data frame

2017-06-12 Thread Rui Barradas

Hello,

Please allways cc the list, don't answer just to me.

Now I'm getting a different error. I had noticed that you have no 
reference to 'TPBDATA' before the call to plspm but I forgot to mention 
it in my first e-mail.



TPB_pls1 = plspm(TPBDATA, TPB_path, TPB_blocks, modes = TPB_modes)
Error in is_tabular(x) : object 'TPBDATA' not found

So we need to know what 'TPBDATA' is.

Rui Barradas

Em 12-06-2017 00:19, Sarah Sinasac escreveu:

Hello Rui,
I must have missed that line when I copied and pasted my code.
Behavioural Beliefs is:
"Behavioural Beliefs" = c(0, 0, 0, 0, 0, 0, 0, 0)

Thank you,
Sarah

On Sun, Jun 11, 2017 at 4:36 PM, Rui Barradas  wrote:

Hello,

Your code throws an error before the line you've mentioned:


library(plspm)

"Attitude" = c(1, 0, 0, 0, 0, 0, 0, 0)

"Normative Beliefs" = c(1, 0, 0, 0, 0, 0, 0, 0)

"Subjective Norm" = c(0, 0, 1, 0, 0, 0, 0, 0)

"Control Beliefs" = c(1, 0, 1, 0, 0, 0, 0, 0)

"Perceived Behavioural Control" = c(0, 0, 0, 0, 1, 0, 0, 0)

"Intention" = c(0, 1, 0, 1, 0, 1, 0, 0)

"Behaviour" = c(0, 0, 0, 0, 0, 0, 1, 0)

TPB_path = rbind(`Behavioural Beliefs`, Attitude, `Normative Beliefs`,
`Subjective Norm`, `Control Beliefs`, `Perceived Behavioural Control`,
Intention, Behaviour)

Error in rbind(`Behavioural Beliefs`, Attitude, `Normative Beliefs`,
`Subjective Norm`,  :
   object 'Behavioural Beliefs' not found


Please correct this error and post what 'Behavioural Beliefs' is.

Hope this helps,

Rui Barradas


Em 11-06-2017 20:16, Sarah Sinasac escreveu:


Hello,
I am new to R and hope I will not seem ignorant in this post. I am
currently using the plspm package by Gaston Sanchez accompanied by his
text book.
I have attempted to create a square matrix, which has seemed
successful. I used the following code:


"Attitude" = c(1, 0, 0, 0, 0, 0, 0, 0)




"Normative Beliefs" = c(1, 0, 0, 0, 0, 0, 0, 0)




"Subjective Norm" = c(0, 0, 1, 0, 0, 0, 0, 0)




"Control Beliefs" = c(1, 0, 1, 0, 0, 0, 0, 0)




"Perceived Behavioural Control" = c(0, 0, 0, 0, 1, 0, 0, 0)




"Intention" = c(0, 1, 0, 1, 0, 1, 0, 0)




"Behaviour" = c(0, 0, 0, 0, 0, 0, 1, 0)




TPB_path = rbind(`Behavioural Beliefs`, Attitude, `Normative Beliefs`,
`Subjective Norm`, `Control Beliefs`, `Perceived Behavioural Control`,
Intention, Behaviour)




colnames(TPB_path) = rownames(TPB_path)




innerplot(TPB_path, box.size = 0.1)



Then I attempted to set up the pls model using the following code (as
directed by the textbook and the r help function):


#outermodel




TPB_blocks = list(1:7, 8:14, 15:21, 22:28, 29:34, 35:39, 40:44, 45:48)




TPB_modes = rep("A", 8)




TPB_pls1 = plspm(TPBDATA, TPB_path, TPB_blocks, modes = TPB_modes)



However, I received the following error (I tried multiple times, and
cannot determine what the error is):

Error in `[.data.frame`(crossloadings, , c("name", "block",
colnames(xloads))) :

undefined columns selected


I would really appreciate if anyone could provide advice on how to
correct this error. I am using the plspm package in order to analyze
my data for my masters thesis at the University of Waterloo.

Thank you!
Sarah

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.





__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] issues in plm using random effect model

2017-06-12 Thread Nina Schönfelder

Dear Kailas Gokhale,

The negative individual variance is not a problem with your code or plm. 
It a property of your data. Please check the posts of Giovanni Millo on 
this topic:


[R] R: plm random effect: the estimated variance of the individual 
effect is negative

Millo Giovanni Giovanni_Millo at Generali.com
Sat Jan 5 10:10:01 CET 2013

You can find the posts in the archive by rseek.org.

Kind regards,

Nina Schönfelder

-
FernUniversität in Hagen
Fakultät für Wirtschaftswissenschaft
Lehrstuhl für Volkswirtschaftslehre,
insbes. Makroökonomik
58084 Hagen

E-Mail: nina.schoenfel...@fernuni-hagen.de
Telefon: +49 2331 987 - 2379
Fax: +49 2331 987 - 391

Hausanschrift:
Informationszentrum (IZ, ehemals TGZ)
Universitätsstr. 11
Raum B110

Am 06.06.2017 um 12:00 schrieb r-help-requ...@r-project.org:

Message: 1
Date: Mon, 5 Jun 2017 15:41:23 +0530
From: Kailas Gokhale
To:r-help@r-project.org
Subject: [R] issues in plm using random effect model
Message-ID:

Re: [R] Beginner’s Question

2017-06-12 Thread Barry Rowlingson
On Mon, Jun 12, 2017 at 2:39 AM, Neil Salkind  wrote:
> Please excuse the naive question but my first hour with RStudio, resulted in 
> this…
>
>> data()
>> data(“women”)
> Error: unexpected input in "data(�”
>
> So,that did not work but
>
>>data(women)
>
> without the quotes did.
>
> Would someone be so kind as to explain the function of quotes in RStudio? 
> Thanks, Neil

First of all this is R, not RStudio. R is the language, the core, it
does all the computation. RStudio is just a pretty wrapper that lets
you click menus and arranges all your windows for you because it
thinks it knows how to arrange windows better than your operating
system. But I digress.

Quotes in R are used to define character strings. You can use single
or double quotes, but the exact same quote mark is used at the start
and finish. Unlike in proper books, R doesn't use "66" quotes at the
start and "99" quotes at the end of a string. Some word processors
will magically change standard plain quotes to super cute 66 and 99
quotes which seems to be how they may have sneaked into your RStudio
session.

Now in R, if you just type a word it usually means the value of the
thing with that name. So there's a difference between:

 x = y

and

 x = "y"

In the first case, x is going to get the value of an object called y,
and if there is no object called y it will error. In the second case x
is going to get the character value "y", and there's no object called
y involved at all. But there are exceptions

The library function is probably the first exception people come
across. You can type:

library(stats)

without using any quotes, and even though there's no object called
stats, you don't get an error. The code in the library function uses
special powers to look at what you typed rather than the value of an
object called stats that you passed to the function. This means that
although there is a package called ggplot2 on my system, this doesn't
work:

 > thing="ggplot2"
 > library(thing)
 Error in library(thing) : there is no package called ‘thing’

It looks for a package called thing rather than one called ggplot2. Surprise!

You *can* pass a character string value to library, so both
library(ggplot2) and  library("ggplot2") both work the same.

The data function is another function that uses the same methods as
library to get what you asked for. So (once you get your quotes
straightened out) you can do:

data(women)

or (double quotes):

data("women")

or (single quotes):

data('women')

Those of us who see this kind of behaviour as an impurity in a
language shudder when we think about it - names are names and strings
are strings - but others are grateful for saving two keystrokes every
time they type library(ggplot2).


> *
> Whenever the people are well informed, they can be trusted with their own 
> government.  ~ ~ ~Thomas Jefferson
>
> Neil J. Salkind
> (785) 841-0947
> neiljsalk...@gmail.com
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] Paths in knitr

2017-06-12 Thread G . Maubach
Hi Yihui,
Hi Duncan,

I corrected my typo. Unfortunately knitr did not find my plots in the 
directory where they reside which is different from the Rmd document.

The documentation of knitr says:

base.dir: (NULL) an absolute directory under which the plots are generate
root.dir: (NULL) the root directory when evaluating code chunks; if NULL, 
the directory of the input document will be used

>From that description I thought, if the base.dir can be used for writng 
plots, it is then also used for reading plots if set? No, it is not.
If I set the root directory to the plots/graphics directory will knitr 
then find my plots? No, it does not.

Reading blog posts my thoughts looked not so strange to me, e.g. 
https://philmikejones.wordpress.com/2015/05/20/set-root-directory-knitr/. 
Unfortunately, it does not work for me.

I am using a RStudio project file. Could it be that this interferes which 
the knitr options?

I tried the solution that Duncan suggested:

c_path_plots <- 
"H:/2017/Analysen/Kundenzufriedenheit/Auswertung/results/graphics

`r knitr::include_graphics(file.path(c_path_plots, 
"email_distribution_pie.png"))`

This solution works fine. I will go with it for this project as I have to 
finish my report soon.

I read Hadley's book on bulding R Packages (
https://www.amazon.de/R-Packages-Hadley-Wickham/dp/1491910593) and found 
it quite complicated and time consuming to build one. Thus I did not try 
yet to build my own packages. At the end of last week I heard from another 
library (http://reaktanz.de/R/pckg/roxyPackage/) which shall make building 
packages much easier. I plan to try that shortly.

On my path to become better in analytics using R, I will try to use 
modules of Rmd files which can then easily be integrated into a Rmd 
report. I have yet to see how I can include these file into a complete 
report.

Kind regards

Georg


- Weitergeleitet von Georg Maubach/WWBO/WW/HAW am 12.06.2017 08:47 
-

Von:Yihui Xie 
An: g.maub...@gmx.de, 
Kopie:  R Help 
Datum:  09.06.2017 20:53
Betreff:Re: [R] Paths in knitr
Gesendet von:   "R-help" 



I'd say it is an expert-only option. If you do not understand what it
means, I strongly recommend you not to set it.

Similarly, you set the root_dir option and I don't know why you did it, 
but
it is a typo anyway (should be root.dir).

Regards,
Yihui
--
https://yihui.name

On Fri, Jun 9, 2017 at 4:50 AM,  wrote:

> Hi Yi,
>
> many thanks for your reply.
>
> Why I do have to se the base.dir option? Cause, to me it is not clear 
from
> the documentation, where knitr looks for data files and how I can adjust
> knitr to tell it where to look. base.dir was a try, but did not work.
>
> Can you give me a hint where I can find information/documentation on 
this
> path issue?
>
> Kind regards
>
> Georg
>
>
> > Gesendet: Donnerstag, 08. Juni 2017 um 15:05 Uhr
> > Von: "Yihui Xie" 
> > An: g.maub...@weinwolf.de
> > Cc: "R Help" 
> > Betreff: Re: [R] Paths in knitr
> >
> > Why do you have to set the base.dir option?
> >
> > Regards,
> > Yihui
> > --
> > https://yihui.name
> >
> >
> > On Thu, Jun 8, 2017 at 6:15 AM,   wrote:
> > > Hi All,
> > >
> > > I have to compile a report for the management and decided to use
> RMarkdown
> > > and knitr. I compiled all needed plots (using separate R scripts)
> before
> > > compiling the report, thus all plots reside in my graphics 
directory.
> The
> > > RMarkdown report needs to access these files. I have defined
> > >
> > > ```{r setup, include = FALSE}
> > > knitr::opts_knit$set(
> > >   echo = FALSE,
> > >   xtable.type = "html",
> > >   base.dir = "H:/2017/Analysen/Kundenzufriedenheit/Auswertung",
> > >   root_dir = "H:/2017/Analysen/Kundenzufriedenheit/Auswertung",
> > >   fig.path = "results/graphics")  # relative path required, see
> > > http://yihui.name/knitr/options
> > > ```
> > >
> > > and then referenced my plot using
> > >
> > > 
> > >
> > > because I want to be able to customize the plotting attributes.
> > >
> > > But that fails with the message "pandoc.exe: Could not fetch
> > > email_distribution_pie.png".
> > >
> > > If I give it the absolute path
> > > "H:/2017/Analysen/Kundenzufriedenheit/Auswertung/results/
> graphics/email_distribution_pie.png"
> > > it works fine as well if I copy the plot into the directory where 
the
> > > report.RMD file resides.
> > >
> > > How can I tell knitr to fetch the ready-made plots from the graphics
> > > directory?
> > >
> > > Kind regards
> > >
> > > Georg
>

 [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 

Re: [R] Keep only those values in a row in a data frame which occur only once.

2017-06-12 Thread Jim Lemon
Hi Ashim,
One way is this, assuming that your data frame is named akdf:

akdf<-t(apply(akdf,1,function(x) return(unique(x)[1:length(x)])))

If you want factors instead of strings, more processing will be required.
Jim

On Mon, Jun 12, 2017 at 3:23 PM, Ashim Kapoor  wrote:
> Dear All,
>
> I have a file data.txt as follows:
>
> Name_1,A,B,C
> Name_2,E,F
> Name_3,I,J,I,K,L,M
>
> I will read this with:
> my_data<- read.csv("data.txt",header=FALSE,col.names=paste0("V",
> seq(1:10)),fill=TRUE)
>
> Then the file will have 10 columns. I am assuming that each row in data.txt
> will have at the max 10 entries.
>
> Note: Here each row will have a different number of columns in data.txt but
> each row will have 10 ( some trailing blank columns ) columns.
>
> My query is how can I keep only the unique elements in each row? For
> example: I want the row 3 to be Name_3,I,J,K,L,M
>
> Please note I don't want the 2nd I to appear.
>
> How can I do this?
>
> Best Regards,
> Ashim
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Beginner’s Question

2017-06-12 Thread Jim Lemon
Hi Meil,
Looks like the old fancy quote problem. You aren't cutting and pasting
text from Word are you?

Jim

On Mon, Jun 12, 2017 at 11:39 AM, Neil Salkind  wrote:
> Please excuse the naive question but my first hour with RStudio, resulted in 
> this…
>
>> data()
>> data(“women”)
> Error: unexpected input in "data(�”
>
> So,that did not work but
>
>>data(women)
>
> without the quotes did.
>
> Would someone be so kind as to explain the function of quotes in RStudio? 
> Thanks, Neil
>
> *
> Whenever the people are well informed, they can be trusted with their own 
> government.  ~ ~ ~Thomas Jefferson
>
> Neil J. Salkind
> (785) 841-0947
> neiljsalk...@gmail.com
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

[R] Beginner’s Question

2017-06-12 Thread Neil Salkind
Please excuse the naive question but my first hour with RStudio, resulted in 
this…

> data()
> data(“women”)
Error: unexpected input in "data(�”

So,that did not work but 

>data(women)

without the quotes did.

Would someone be so kind as to explain the function of quotes in RStudio? 
Thanks, Neil

*
Whenever the people are well informed, they can be trusted with their own 
government.  ~ ~ ~Thomas Jefferson

Neil J. Salkind
(785) 841-0947
neiljsalk...@gmail.com


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R-es] package ‘rgdal’ is not available (for R version 3.2.3)

2017-06-12 Thread miguel.angel.rodriguez.muinos
Hola Javier Valdes

Efectivamente, tiene razón Carlos; rgdal necesita como mínimo la versión
3.3.0 de R

https://cran.r-project.org/web/packages/rgdal/index.html

Un Saludo.



El 12/06/2017 a las 8:30, Carlos J. Gil Bellosta escribió:
> Prueba con una versión no antigua de R.
>
> El lun., 12 jun. 2017 4:36, javier valdes  escribió:
>
>> Estimados:
>> Es posible solucionar este tema?? He probado con varias alternativas
>> disponibles en internet, pero ninguna me ha funcionado aun.
>> Saludos.






Nota: A información contida nesta mensaxe e os seus posibles documentos 
adxuntos é privada e confidencial e está dirixida únicamente ó seu 
destinatario/a. Se vostede non é o/a destinatario/a orixinal desta mensaxe, por 
favor elimínea. A distribución ou copia desta mensaxe non está autorizada.

Nota: La información contenida en este mensaje y sus posibles documentos 
adjuntos es privada y confidencial y está dirigida únicamente a su 
destinatario/a. Si usted no es el/la destinatario/a original de este mensaje, 
por favor elimínelo. La distribución o copia de este mensaje no está autorizada.

See more languages: http://www.sergas.es/aviso-confidencialidad
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] package ‘rgdal’ is not available (for R version 3.2.3)

2017-06-12 Thread Carlos J. Gil Bellosta
Prueba con una versión no antigua de R.

El lun., 12 jun. 2017 4:36, javier valdes  escribió:

> Estimados:
> Es posible solucionar este tema?? He probado con varias alternativas
> disponibles en internet, pero ninguna me ha funcionado aun.
> Saludos.
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es