[R] Use of C functions inside the DLL object

2018-11-19 Thread Cleber N.Borges via R-help

hello everybody and good night ...
I'm trying to learn how to use a DLL, via "dyn.load" and ".C" inside the R.
I did some testing (below is a part of what I tried) and I could not 
figure out how to do this.
If anyone can give a hint on how to do this manipulation, it would be a 
lot of help!

And thanks in advance for any tip.
Thank you!
Cleber

###

In the pdf explaining the SDK, it has function detail:

FDwfGetVersion(char szVersion[32])
Description: Retrieves the version string. The version string is 
composed of major, minor, and build numbers (i.e.,

“2.0.19”).


##

### In R, I tried:

> dwf <- dyn.load("C:\\Windows\\System32\\dwf")
> is.loaded("FDwfGetVersion")
[1] TRUE
> result <- .C("FDwfGetVersion", version=as.character() )
> result
$`version`
character(0)

> str(result)
List of 1
 $ version: chr(0)

#

But in Python, I saw that the result is as follows (examples in Python 
are made available by the manufacturer)


#

>>> from ctypes import *
>>> dwf = cdll.dwf
>>> version = create_string_buffer(16)
>>> dwf.FDwfGetVersion(version)
1
>>> print("DWF Version: "+str(version.value))
DWF Version: 3.8.22
>>>








---
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus
__
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] plot one levelplot over another

2018-11-19 Thread Waichler, Scott R
Hi, I am using levelplot() to plot a primary response surface, z1.  I wish to 
write a custom panel function that will let me plot another surface z2 = f(x,y) 
over z1.  The second surface z2 is either NA or 1, and at locations where z2 = 
1, I will use a color with low alpha to let the the z1 surface show through.  
How can I do this?

Regards,
Scott Waichler
Pacific Northwest National Laboratory
Richland, WA 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.


Re: [R] unique() duplicate() not what i am looking for

2018-11-19 Thread Fox, John
Dear Knut,

Here's one way:

> as.vector((table(Dup) > 1)[Dup])
[1]  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE FALSE

Someone will probably think of something cleverer.

I hope this helps,
 John

--
John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
Web: socialsciences.mcmaster.ca/jfox/



> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Knut
> Krueger
> Sent: Monday, November 19, 2018 9:42 AM
> To: r-help@r-project.org >> r-help mailing list 
> Subject: [R] unique() duplicate() not what i am looking for
> 
> It should be simple but i do not find the right keywords:
> 
> 
> Dup =  c(1,2,3,4,1,2,3,5)
> 
> I need 4,5 as result
> 
> unique(Dup) gives me [1] 4 1 2 3 5
> 
> duplicated(Dup) gives me
> [1] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE
> 
> I need
> [1] TRUE TRUE TRUE FALSE  TRUE  TRUE  TRUE FALSE
> 
> 
> Kind regards Knut
> 
> __
> 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] unique() duplicate() not what i am looking for

2018-11-19 Thread Rui Barradas

Hello,

Try

i <- !(duplicated(Dup) | duplicated(Dup, fromLast = TRUE))
Dup[i]


or in one line, I post it like this to make it more clear.

Hope this helps,

Rui Barradas

Às 14:41 de 19/11/2018, Knut Krueger escreveu:

It should be simple but i do not find the right keywords:


Dup =  c(1,2,3,4,1,2,3,5)

I need 4,5 as result

unique(Dup) gives me [1] 4 1 2 3 5

duplicated(Dup) gives me
[1] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE

I need
[1] TRUE TRUE TRUE FALSE  TRUE  TRUE  TRUE FALSE


Kind regards Knut

__
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] unique() duplicate() not what i am looking for

2018-11-19 Thread PIKAL Petr
Hi

and maybe sloightly less complicated

setdiff(Dup,Dup[duplicated(Dup)])

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of Knut Krueger
> Sent: Monday, November 19, 2018 3:42 PM
> To: r-help@r-project.org >> r-help mailing list 
> Subject: [R] unique() duplicate() not what i am looking for
>
> It should be simple but i do not find the right keywords:
>
>
> Dup =  c(1,2,3,4,1,2,3,5)
>
> I need 4,5 as result
>
> unique(Dup) gives me [1] 4 1 2 3 5
>
> duplicated(Dup) gives me
> [1] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE
>
> I need
> [1] TRUE TRUE TRUE FALSE  TRUE  TRUE  TRUE FALSE
>
>
> Kind regards Knut
>
> __
> 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.
Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních 
partnerů PRECHEZA a.s. jsou zveřejněny na: 
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about 
processing and protection of business partner’s personal data are available on 
website: https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a 
podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: 
https://www.precheza.cz/01-dovetek/ | This email and any documents attached to 
it may be confidential and are subject to the legally binding disclaimer: 
https://www.precheza.cz/en/01-disclaimer/

__
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] unique() duplicate() not what i am looking for

2018-11-19 Thread PIKAL Petr
Hi

Dup %in% Dup[duplicated(Dup)]

Dup[!(Dup %in% Dup[duplicated(Dup)])]

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of Knut Krueger
> Sent: Monday, November 19, 2018 3:42 PM
> To: r-help@r-project.org >> r-help mailing list 
> Subject: [R] unique() duplicate() not what i am looking for
>
> It should be simple but i do not find the right keywords:
>
>
> Dup =  c(1,2,3,4,1,2,3,5)
>
> I need 4,5 as result
>
> unique(Dup) gives me [1] 4 1 2 3 5
>
> duplicated(Dup) gives me
> [1] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE
>
> I need
> [1] TRUE TRUE TRUE FALSE  TRUE  TRUE  TRUE FALSE
>
>
> Kind regards Knut
>
> __
> 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.
Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních 
partnerů PRECHEZA a.s. jsou zveřejněny na: 
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about 
processing and protection of business partner’s personal data are available on 
website: https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a 
podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: 
https://www.precheza.cz/01-dovetek/ | This email and any documents attached to 
it may be confidential and are subject to the legally binding disclaimer: 
https://www.precheza.cz/en/01-disclaimer/

__
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] unique() duplicate() not what i am looking for

2018-11-19 Thread Knut Krueger

It should be simple but i do not find the right keywords:


Dup =  c(1,2,3,4,1,2,3,5)

I need 4,5 as result

unique(Dup) gives me [1] 4 1 2 3 5

duplicated(Dup) gives me
[1] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE

I need
[1] TRUE TRUE TRUE FALSE  TRUE  TRUE  TRUE FALSE


Kind regards Knut

__
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] Request for aid in first R script

2018-11-19 Thread S Ellison
Pointers inline below:

> > Since I'm a newbie on R, I was wondering if you could help me to achieve a
> > small project that I think it's possible with this project (I cant seem to
> > find a similar tool)
> >
> > I have a data file with about 2000 value lines, organized like this:
> >
> > x;y;z;j;
> > ...
> >
> > I want to find diferent correlations (linear regression with
> > Levenberg–Marquardt or least squares) between the x values and a y or z
> > pair. For instance, between x and y.
> >
> > So, what I'm trying to do is:
> >
> > 1) Load the file (is there a limit on the load size? If yes, can I load it
> > in sequence by parts?)
See ?read.table and note that you can define a separator. Using read.table() 
with sep=";" should work
Load limits are memory size; I have read 800,000 lines on a 4Gb system

> > 2) Define 100 sets of 20 values each (also sequence, from x1 to xn: first
> > from x1 to x20, next from x21 to x41, etc.) or process one set at the time
> > in case of file limits in 1)
You can say something like
mydata[i:(i+20), ]
to get row-wise slices of your data, but an R user would perhaps consider 
setting up an ancillary variable using
mydata$chunks <- gl(100,20)
and use a variant of aggregate() or ddply to apply a function to each subset

> > 3) Define a fitting function
er... anything you can write, either as an expression or a function.

> > 4) Use the same function model to find the best fit for each set
Look at, for example, lm for linear models (including polynomials), nls or nlm 
for non-linear models, and a decent book on R for a much, much, much wider 
range, including splines, generalised additive models, generalised linear 
models, mixed effects models (linear and otherwise) ...

> > 5) Save in a file, the coefficients of those fits.
Something like sapply or ddply should be able to give you a table of 
coefficients, especially if you write a wrapper function like
mywrap <- function(x) coef( nls(y~fitfun)) 
to return a vector of coefficients from a chunk x

> > Can this be done accurately with R?
Yes; R has well-characterised numerically stable core functions, which is more 
than can be said for most spreadsheets.

> > It would save me a lot of programming. 
You'll still have to do that, but doing it in R will be a lot faster than C

> > The files will soon have about 1
> > million lines, which is a lot to process.
If you can’t load it all at once, you can use read.table with start and end 
rows.
or you can puch the whole lot to a database and use any of R's database 
packages to read from that; Rmysql and the like.



***
This email and any attachments are confidential. Any use, copying or
disclosure other than by the intended recipient is unauthorised. If 
you have received this message in error, please notify the sender 
immediately via +44(0)20 8943 7000 or notify postmas...@lgcgroup.com 
and delete this message and any copies from your computer and network. 
LGC Limited. Registered in England 2991879. 
Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK
__
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] Request for aid in first R script

2018-11-19 Thread Thierry Onkelinx via R-help
Dear Kepler,

Yes, R can do this all. But this is is to help you when you get stuck, not
to do all the work for you... You are asking basic stuff, so any
introduction book on R should contain sufficient information to get you
going. So please do read on of those first.

Best regards,

ir. Thierry Onkelinx
Statisticus / Statistician

Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND
FOREST
Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
thierry.onkel...@inbo.be
Havenlaan 88 bus 73, 1000 Brussel
www.inbo.be

///
To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
///




Op ma 19 nov. 2018 om 11:39 schreef Rui Fernandes :

> Good morning
>
> My compliments to all.
>
> Since I'm a newbie on R, I was wondering if you could help me to achieve a
> small project that I think it's possible with this project (I cant seem to
> find a similar tool)
>
> I have a data file with about 2000 value lines, organized like this:
>
> x;y;z;j;
> ...
>
> I want to find diferent correlations (linear regression with
> Levenberg–Marquardt or least squares) between the x values and a y or z
> pair. For instance, between x and y.
>
> So, what I'm trying to do is:
>
> 1) Load the file (is there a limit on the load size? If yes, can I load it
> in sequence by parts?)
> 2) Define 100 sets of 20 values each (also sequence, from x1 to xn: first
> from x1 to x20, next from x21 to x41, etc.) or process one set at the time
> in case of file limits in 1)
> 3) Define a fitting function
> 4) Use the same function model to find the best fit for each set
> 5) Save in a file, the coefficients of those fits.
>
> Can this be done accurately with R?
>
> It would save me a lot of programming. The files will soon have about 1
> million lines, which is a lot to process.
>
> I would apreciate very much if someone could help me.
>
> Kind regards
>
> Kepler
>
> [[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] subset English language using textcat package

2018-11-19 Thread Robert David Burbidge via R-help

Look at the help docs and examples for textcat and sapply:

print(as.character(data$x[sapply(data$x, textcat)=="english"]))

Although textcat defaults classify "This book is amazing" as dutch, so 
you may want to read the help for textcat and change the profile db 
("p") or "method".


On 19/11/2018 09:48, Elahe chalabi via R-help wrote:

Hi all,

How is it possible to subset English text from a df containing German and 
English texts using textcat package?



 > library(textcat)
 > dput(data)
 structure(list(x = structure(c(2L, 6L, 5L, 3L, 1L, 4L), .Label = c("Dieses Buch 
ist erstaunlich",
 "I love this book", "ich liebe dieses Buch", "mehrere bücher in prozess",
 "several books in proccess", "This book is amazing"), class = "factor")), 
row.names = c(NA,
 -6L), class = "data.frame")

I want the output to be like the following:


 "I love this book"  "This book is amazing"  "several books in proccess"


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] Request for aid in first R script

2018-11-19 Thread Rui Fernandes
Good morning

My compliments to all.

Since I'm a newbie on R, I was wondering if you could help me to achieve a
small project that I think it's possible with this project (I cant seem to
find a similar tool)

I have a data file with about 2000 value lines, organized like this:

x;y;z;j;
...

I want to find diferent correlations (linear regression with
Levenberg–Marquardt or least squares) between the x values and a y or z
pair. For instance, between x and y.

So, what I'm trying to do is:

1) Load the file (is there a limit on the load size? If yes, can I load it
in sequence by parts?)
2) Define 100 sets of 20 values each (also sequence, from x1 to xn: first
from x1 to x20, next from x21 to x41, etc.) or process one set at the time
in case of file limits in 1)
3) Define a fitting function
4) Use the same function model to find the best fit for each set
5) Save in a file, the coefficients of those fits.

Can this be done accurately with R?

It would save me a lot of programming. The files will soon have about 1
million lines, which is a lot to process.

I would apreciate very much if someone could help me.

Kind regards

Kepler

[[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] subset English language using textcat package

2018-11-19 Thread Elahe chalabi via R-help
Hi all, 

How is it possible to subset English text from a df containing German and 
English texts using textcat package?



> library(textcat)
> dput(data) 
structure(list(x = structure(c(2L, 6L, 5L, 3L, 1L, 4L), .Label = c("Dieses 
Buch ist erstaunlich", 
"I love this book", "ich liebe dieses Buch", "mehrere bücher in prozess", 
"several books in proccess", "This book is amazing"), class = "factor")), 
row.names = c(NA, 
-6L), class = "data.frame")

I want the output to be like the following:


"I love this book"  "This book is amazing"  "several books in proccess"


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.