Re: [R] "--" < 0

2024-06-25 Thread Adrian Dusa
Oh I see...
It's not that "-7" gets coerced to numeric, but 0 gets coerced to "0".
Of course...

On Tue, Jun 25, 2024 at 11:02 AM Martin Maechler 
wrote:

> >>>>> Adrian Dusa
> >>>>> on Tue, 25 Jun 2024 10:56:07 +0300 writes:
>
> > Dear R fellows,
>
> >> From time to time, just when I thought I knew my R, I get
> >> bitten by some
> > small things that reminds one to constantly return to the
> > basics.
>
> > I knew for instance that "-1" < 0 is TRUE, presumably
> > because R first coerces to numeric before comparing with
> > 0.
>
> > But I did not expect that "--" < 0 is a TRUE statement.
> > (and the same holds for any string prepended by a minus
> > sign, e.g. "-a" < 0)
>
> > I would be grateful for an explanation, I'm sure that
> > something very obvious escapes me but it sure does seem
> > counter intuitive to me.
>
> > Best wishes, Adrian
>
> >   [[alternative HTML version deleted]]
>
> Nice, quiz, yes.
>
> You must have forgotten that all Op's (+,-, <= , &, | ..)
> must coerce to common type.
>
> ... and so does  c()  where coercion is defined a bit more.
>
> -->  does  c("--", 0)   give you a clue, now ?
>

[[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] "--" < 0

2024-06-25 Thread Adrian Dusa
Dear R fellows,

>From time to time, just when I thought I knew my R, I get bitten by some
small things that reminds one to constantly return to the basics.

I knew for instance that "-1" < 0 is TRUE, presumably because R first
coerces to numeric before comparing with 0.

But I did not expect that "--" < 0 is a TRUE statement.
(and the same holds for any string prepended by a minus sign, e.g. "-a" < 0)

I would be grateful for an explanation, I'm sure that something very
obvious escapes me but it sure does seem counter intuitive to me.

Best wishes,
Adrian

[[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] replacing unicode characters

2023-06-30 Thread Adrian Dusa
Right on the point, Ivan, that was the issue. The output from l10n_info()
was:

$MBCS
[1] FALSE

$`UTF-8`
[1] FALSE

$`Latin-1`
[1] FALSE

$codeset
[1] "US-ASCII"

(and the locale was just "C")

I simply needed to write something like:
export LC_ALL='en_US.UTF-8'

before starting the child process, and everything looks good now.

Thanks a lot, much obliged,
Adrian


On Fri, Jun 30, 2023 at 2:10 PM Ivan Krylov  wrote:

> On Fri, 30 Jun 2023 11:33:34 +0300
> Adrian Dușa  wrote:
>
> > In a very simple test, I tried creating a text file from the Electron
> > app embedded R:
> > sink("test.txt")
> > cat("\u00e7")
> > sink()
> >
> > which resulted in:
> >
> > 
> >
> > I don't quite understand how this works, my best guess is it matters
> > less how R interprets these characters, but how they are passed
> > through the child process that started R.
>
> Something goes wrong with the locale setting when the R child process
> is being launched. For example,
>
> Rscript -e 'cat("\ue7\n")'
> # ç
>
> but:
> LC_ALL=C Rscript -e 'cat("\ue7\n")'
> # 
>
> When preparing \ue7 for output, R decides that it's not representable
> in the session encoding. What's the output of sessionInfo() and
> l10n_info() in the child process?
>
> --
> Best regards,
> Ivan
>

[[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] [R-pkgs] new version of QCA

2012-04-10 Thread Adrian Dusa
Dear All,

I have just uploaded a new version of the QCA (Qualitative Comparative
Analysis) on CRAN, and it will be propagated in a couple of days.

This is version 1.0-0 ("Easter edition") of the package, straight from
the previous version 0.6-5, and it represent a major re-write of the
package in order to accomodate fuzzy-sets. I am pleased to welcome
Alrik Thiem as a co-author of this package, his skills and knowledge
have been paramount to developing the current code.

This version has numerous changes in the code (probably too many to
present in this email) and new additional functions. Most notably, the
previous qmcc() function is now obsolete, given that all our tests
have shown that eqmcc() yield the same exact results but it's by far
superior in speed.

A very happy Easter, and happy QCA-ing,
Adrian and Alrik

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
       +40 21 3120210 / int.101
Fax: +40 21 3158391

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


Re: [R] For-loop dummy variables?

2010-10-19 Thread Adrian Dusa
On Tuesday 19 October 2010, Phil Spector wrote:
> I always find R useful to solve problems like this:
> 
>dummy = as.numeric(cleary$D1 %in% c(4,6,7))

Indeed, and this works too:
dummy <- 1*(cleary$D1 %in% c(4,6,7))

Adrian 

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391

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


Re: [R] For-loop dummy variables?

2010-10-19 Thread Adrian Dusa
gravityflyer  yahoo.com> writes:
> 
> Hi everyone, 
> 
> I've got a dataset with 12,000 observations. One of the variables
> (cleary$D1) is for an individual's country, coded 1 - 15. I'd like to create
> a dummy variable for the Baltic states which are coded 4,6, and 7. In other
> words, as a dummy variable Baltic states would be coded 1, else 0.  I've
> attempted the following for loop:
> 
> dummy <- matrix(NA, nrow=nrow(cleary), ncol=1)
> for (i in 1:length(cleary$D1)){
>   if (cleary$D1 == 4){dummy[i] = 1}
>   else {dummy[i] = 0}
>   }
> 
> Unfortunately it generates the following error:
> 
> 1: In if (cleary$D1 == 4) { ... :
>   the condition has length > 1 and only the first element will be used
> 
> Another options I've tried is the following:
> 
> binary <- vector(length=length(cleary$D1))
> for (i in 1:length(cleary$D1)) {
>   if (cleary$D1 == 4 | cleary$D1 == 6 | cleary$D1 == 7 ) {binary[i] = 1}
>   else {binary[i] = 0}
> }
> 
> Unfortunately it simply responds with "syntax error".
> 
> Any thoughts would be greatly appreciated!
> 

Be aware that R is a vectorised programming language, therefore your for loop 
in 
completely unnecessary.

This is what I'd do:

dummy <- rep(0, nrow(cleary))
dummy[cleary$D1 %in% c(4,6,7)] <- 1

This is your dummy variable.
Below is your working (though VERY inefficient) version of the for loop:

binary <- vector(length=length(cleary$D1))
for (i in 1:length(cleary$D1)) {
if (cleary$D1[i] == 4 | cleary$D1[i] == 6 | cleary$D1[i] == 7 ) {
binary[i] = 1
} else {
binary[i] = 0
}
}

Now try to figure out:
- what is the difference between your for() loop and mine?
- which code is more simple (and better), the vectorised or the for() loop?

I hope it helps,
Adrian

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


Re: [R] looking for .. dec if vector if element > x

2010-05-18 Thread Adrian Dusa
On Tuesday 18 May 2010, Knut Krueger wrote:
> Hi to all,
> I am just looking for more efficient ways ;-)
> 
> is there a better way instead a loop  to decrease x if greater y
> test  <- c(1,3,5,7,9)
> 
> decrease if greater 1 to
> test2  <- c(1,2,4,6,8)

Does this help?

> test  <- c(1, 3, 5, 7, 9)
> test[test > 1] <- test[test > 1] - 1
> test
[1] 1 2 4 6 8

Adrian

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391

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


Re: [R] Question about factor that is numeric, in aov()

2010-05-09 Thread Adrian Dusa
Dear Ravi,

On Sunday 09 May 2010, Ravi Kulkarni wrote:
> I notice something curious about how aov() treats a numeric factor:

In R, there is no such thing as a "numeric factor". A numeric vector is not a 
factor unless declared as such.


> "score" is a dependent variable and "group" is a factor in a one-way ANOVA.
> But "group" contains numeric codes and is not a factor (checked with
> 
> is.factor). An ANOVA done using:
> > aov(score~factor(group), data=mydata)
> 
> gives the right answers. But
> 
> > aov(score~group, data=mydata)
> 
> also produces an ANOVA table, with incorrect entries. My question is: what
> exactly is R doing when I did not specify that "group" was a factor?

The entries _are_ correct, because "group" is numeric.
From the help of aov():

Details:

 This provides a wrapper to ‘lm’ for fitting linear models to
 balanced or unbalanced experimental designs.

So aov() calls lm(), where it is mighty important whether "group" is numeric 
or factor. There are both in your mind, but in R you have to declare it as 
factor in order to treat it as such...

I hope this helps,
Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391

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


Re: [R] counting the number of times a string appears

2010-01-13 Thread Adrian Dusa
Hi Jesse,

If your vector is called "aa", then how about:

> table(aa)
aa
 spp1 spp10  spp2  spp3  spp4  spp5  spp6  spp7  spp8  spp9
7 216 815 9 910 915

Hope this helps,
Adrian


On Thursday 14 January 2010, Jesse Sinclair wrote:
> Hi all,
> 
> I have a vector of strings and need to count the number of times a string
> appears in the vector.
> 
> eg:
> 
>  [1] spp6  spp10 spp6  spp6  spp4  spp2  spp9  spp10 spp5  spp2  spp2  spp3
>  [13] spp4  spp3  spp6  spp10 spp6  spp4  spp9  spp3  spp6  spp1  spp10
>  spp8
> 
>  [25] spp2  spp10 spp9  spp7  spp1  spp3  spp8  spp6  spp3  spp8  spp6 
>  spp5
> 
>  [37] spp5  spp9  spp3  spp1  spp4  spp5  spp9  spp3  spp3  spp5  spp4 
>  spp9
> 
>  [49] spp3  spp7  spp7  spp2  spp6  spp5  spp7  spp4  spp8  spp9  spp2 
>  spp6
> 
>  [61] spp3  spp3  spp2  spp6  spp3  spp5  spp6  spp6  spp4  spp1  spp1 
>  spp1
> 
>  [73] spp10 spp8  spp1  spp6  spp1  spp5  spp8  spp9  spp5  spp6  spp9
> spp10
>  [85] spp2  spp6  spp10 spp1  spp2  spp3  spp5  spp8  spp2  spp7  spp4 
>  spp7
> 
>  [97] spp2  spp6  spp2  spp6
> 
> Is it possible to create a vector of counts for each spp1-spp10?
> 
> Any help or ideas would be appreciated.
> 
> Cheers,
> Jesse
> 
>   [[alternative HTML version deleted]]
> 


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391

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


Re: [R] merging issue.........

2010-01-13 Thread Adrian Dusa
Hi Karean,

If your first object is called obj1 and the second called obj2, then:

> merge(obj1, obj2, all.x=TRUE)
  id trait1 trait2
1  1   10.29.8
2  2   11.1   10.8
3  39.7 NA
4  6   10.2   10.1
5  78.9 NA
6 109.7 NA
7 11   10.2 NA

Hope this helps,
Adrian

On Wednesday 13 January 2010, karena wrote:
> hi, I have a question about merging two files.
> For example, I have two files, the first file is like the following:
> 
> id   trait1
> 110.2
> 211.1
> 39.7
> 610.2
> 78.9
> 10  9.7
> 11  10.2
> 
> The second file is like the following:
> idtrait2
> 1 9.8
> 2 10.8
> 4 7.8
> 5 9.8
> 6 10.1
> 1210.2
> 1310.1
> 
> now I want to merge the two files by the variable "id", I only want to keep
> the "id"s which show up in the first file. Even the "id" does not show up
>  in the second file, it doesn't matter, I can keep the missing values. So
>  my question is: how can I merge the two files and keep only the rows whose
>  "id" show up in the first file?
> I know how to do it is SAS, just use the following code:
> merge data1(in=in1) data2(in=in2);
> by id;
> if in1;
> 
> but I really have no idea about how to do it in R.
> 
> thank you in advance,
> 
> karean
> 


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391

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


[R] install.packages error

2009-12-07 Thread Adrian Dusa

Dear listeRs,

I am trying to install a package from the command line, using 
install.packages(). Specifying all the parameters, I simply get this error:

> r <- getOption("repos")
> install.packages("rJava", dependencies=T, repos=r, lib="/home/adi/myRlib")
Error: subscript out of bounds


Additional info about my system (Kubuntu 9.10):
> sessionInfo()
R version 2.10.0 (2009-10-26)
i486-pc-linux-gnu

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

loaded via a namespace (and not attached):
[1] tcltk_2.10.0 tools_2.10.0

Thanks in advance for any hint,
Adrian

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391

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


[R] [R-pkgs] New version of QCA

2009-09-20 Thread Adrian Dusa

Hi,

A new version of the QCA package (0.6-0) was submitted to CRAN.
This is a major improvement, now working with multi-valued data (previous 
versions accepted binary data only).
The "classical" function qmcc() still accepts only binary data, but the 
enhanced function eqmcc() is now ready for mvQCA.

The QCA package performs the Quine-McCluskey algorithm for Qualitative 
Comparative Analysis.

As usual, any suggestions and bug reports are welcomed.

Adrian

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391


[[alternative HTML version deleted]]

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

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


Re: [R] RMySQL - overwrite record, not table

2009-08-24 Thread Adrian Dusa


whizvast wrote:
> 
> Hi, Adrian-
> 
> If you use "overwrite=T" parameter, you will overwrite the entire table,
> not each record. this is the essence of my problem and i still haven't
> found out right solution. i am thinking of writing my own MySQLwriteTable
> function...
> 
> Thank you for your answer anyway!
> 

Sorry for the late reply (I'm on my vacation). If you want to replace a
variable instead of the whole dataframe, I wrote a function about a year ago
and I used it succesfully a few times.
Try this:

"dbUpdateVars" <-
function(conn, dbtable, dataframe=NULL, primary, vars) {
if (!dbExistsTable(conn, dbtable)) {
stop("The target table \"", dbtable, "\" doesn't exist in the
database \"", dbGetInfo(conn)$dbname, "\"\n\n", call. = FALSE)
}
if (is.null(dataframe)) {
stop("The source dataframe is missing, with no default\n\n", call. =
FALSE)
}
if (!(toupper(primary) %in% toupper(names(dataframe {
stop("The primary key variable doesn't exist in the source
dataframe\n\n", call. = FALSE)
}
if (!all(toupper(vars) %in% toupper(names(dataframe {
stop("One or more variables don't exist in the source
dataframe\n\n", call. = FALSE)
}
if (!(toupper(primary) %in% toupper(dbListFields(con, dbtable {
stop("The primary key variable doesn't exist in the target
table\n\n", call. = FALSE)
}
if (!all(toupper(vars) %in% toupper(dbListFields(con, dbtable {
stop("One or more variables don't exist in the target table\n\n",
call. = FALSE)
}
 
if(length(vars) > 1) {
pastedvars <- paste("'", apply(dataframe[, vars], 1, paste,
collapse="', '"), "'", sep="")
}
else {
pastedvars <- paste("'", dataframe[, vars], "'", sep="")
}

varlist <- paste(dbtable, "(", paste(c(primary, vars), collapse=", "),
")", sep="")
datastring <- paste("(", paste(paste(dataframe[, primary], pastedvars,
sep=", "), collapse="), ("), ")", sep="")
toupdate <- paste(paste(vars, "=VALUES(", vars, ")", sep=""),
collapse=", ")   

sqlstring <- paste("INSERT INTO", varlist, "VALUES", datastring, "ON
DUPLICATE KEY UPDATE", toupdate)
dbSendQuery(conn, sqlstring)
}

I hopw it helps you,
Adrian



-- 
View this message in context: 
http://www.nabble.com/RMySQL---overwrite-record%2C-not-table-tp24870097p25120044.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] RMySQL - overwrite record, not table

2009-08-18 Thread Adrian Dusa


whizvast wrote:
> 
> Hi, useR-
> 
> In RMySQL, how do I overwrite records? (equivalent to "replace" query).
> For example, suppose that dat2 is a newer data.frame than dat1. 
> 
> con <- dbConnect(MySQL())
> res <- dbWriteTable(con, "DBname", dat1, row.names=F, append=T, replace=T)
> res <- dbWriteTable(con, "DBname", dat2, row.names=F, append=T, replace=T)
> 
> This would not update/replace the dat1 records in "DBname" with newer
> records from dat2. 
> How would you solve the problem? Thanks=
> 

In case it isn't too late (it's vacation time around), try:

dbWriteTable(con, "DBname", dat2, overwrite=TRUE, row.names=FALSE)

I believe you are confusing "DBname" with the DATABASE from the MySQL which
is not specified here but in dbConnect(). A correct (and complete)
connection to the MySQL should specify the database as well; for example:

con <- dbConnect(drv, user="myusername", password="mypass",
dbname="mydatabase", host="xxx.xxx.xxx.xxx")

Here, the "dbname" argument specifies the database used, the equivalent of
USE command in MySQL.
If "DBname" refers to a table in the database used with dbConnect(), then
the first command of dbWriteTable() that I indicated (without your "res <-",
it's a pure command to the MySQL connection, which should not be saved into
an object) will replace the table "DBname" with your "dat2" table.

I hope it helps,
Adrian

-- 
View this message in context: 
http://www.nabble.com/RMySQL---overwrite-record%2C-not-table-tp24870097p25024769.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Memory errors when using QCA package

2009-07-23 Thread Adrian Dusa
Allan Engelhardt  cybaea.com> writes:
> 
> It is a little stupid, but the length of a vector is limited to 2^31-1 
> entries on any platform.  A matrix is stored as a vector, so the product 
> of all dimensions is also limited to 2^31-1.
> 
> Allan.
> 
> Matthew Gwynne wrote:
> > Hi,
> >
> > I have been using the QCA package, in particular the "eqmcc" function
> > and I am having some issues when trying to use this to minimise a
> > particular boolean function.
> >
> > The  boolean function in question has 16 variables, and I am providing
> > the full truth table for the function (65536 with 256 true entries),
> > in the following way :\
> > [...snip...]

Indeed, thanks very much Allan.
There is a question though for Matthew: why do you try to provide the full truth
table? The function eqmcc() proves its strength exactly for the cases when most
of the causal combinations are unknown (as I believe it is your case).
I would suggest to run the analysis using only the observed combinations, and
eqmcc() will know what to do next.

QCA accepts both truth tables and observed combinations as entry data, but (as
you can see), there are limitations for extemely large truth tables. Should you
need further assistance, I'd be glad to help.

I hope this helps,
Adrian

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


Re: [R] re ad.table, row.names arg

2009-06-05 Thread Adrian Dusa



Markus Loecher-4 wrote:
> 
> Dear R users,
> I had somehow expected that read.table() would treat the column specified
> by
> the row.names argument as of class character. That seems to be the only
> sensible class allowed for a column containing row names. However, that
> does
> not seem to be the case, as the following example shows:
> 
>   x <- cbind.data.frame(ID = c("010007787048271871", "1007109516820319",
> "10094843652996959", "010145176274075487"), X1 = 1:4, X2 = 4:1)
> [...snip...]
> 

As a better alternative, why not move directly the first column in the
rownames?

rownames(x) <- x$ID
write.table(x[, -1], "tmp.txt")
y <- read.table("tmp.txt", header=T)
y
   X1 X2
010007787048271871  1  4
10071095168203192  3
10094843652996959   3  2
010145176274075487  4  1

In this case, X1 and X2 variables are read as numeric, while the first
column is read as character and assigned directly to the rownames.

HTH,
Adrian
-- 
View this message in context: 
http://www.nabble.com/read.table%2C-row.names-arg-tp23888975p23892826.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] read.table, row.names arg

2009-06-05 Thread Adrian Dusa
Markus Loecher  gmail.com> writes:

> [...]
> > x
>   ID X1 X2
> 1 010007787048271871  1  4
> 2   1007109516820319  2  3
> 3  10094843652996959  3  2
> 4 010145176274075487  4  1
> 
> The first column was not read in as a string, which mangled the IDs.
> I could use colClasses explicitly, but then I would need to know the number
> and classes of the remaining columns in advance.
> Is this a bug or expected behavior ?
> Any advice would be most helpful.

You could use a generic colClasses for all columns, like:

y <- read.table("tmp.txt", header= TRUE, row.names=1, colClasses="character")
y
   X1 X2
010007787048271871  1  4
10071095168203192  3
10094843652996959   3  2
010145176274075487  4  1

In this case, all columns are read as character and need to be converted
manually, but your row names are appropriate.

Hoping this helps,
Adrian

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


Re: [R] exporting data to csv file -problem with column names

2009-06-01 Thread Adrian Dusa
Steven Matthew Anderson  mac.com> writes:
> [...]
> Is there a way to exclude the row numbers from the exported csv file?   
> Or add a column name for row number to keep this from happening?

Steven, see the "row.names" argument in write.table(), set it to FALSE.
Adrian

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


Re: [R] Help needed on R output

2009-05-26 Thread Adrian Dusa


A simpler solution:
my.string <- c("",
"01001001011011101100",
"1001001011010101",
"1101110100000011",
"000100100101001001011001",
"000101101101101001101001")

my.string <- paste(my.string, collapse="\",\n\"")

cat(paste("rom_array := (\n\"", my.string, "\")\n", sep=""))

Which produces:
rom_array := (
"",
"01001001011011101100",
"1001001011010101",
"1101110100000011",
"000100100101001001011001",
"000101101101101001101001")

Search in the archives for character escaping to understand the syntax.

A simple example (notice the gradual additions):
aa <- "010"
cat(aa) # 010

bb <- "\"010"
cat(bb) # "010

cc <- "\"010\""
cat(cc) # "010"

Also read the help for ?paste, and notice the difference between the "sep"
and "collapse" arguments.

Hth,
Adrian



Linlin Yan wrote:
> 
>> t <- c(
> + "",
> + "01001001011011101100",
> + "1001001011010101",
> + "1101110100000011",
> + "000100100101001001011001",
> + "000101101101101001101001")
>> {
> + cat ('rom_array := (\n');
> + for (i in 1:length(t)) {
> +   cat('"', t[i], '"',
> + ifelse(i == length(t), '', ',\n'), sep='')
> + };
> + cat(')\n');
> + }
> rom_array := (
> "",
> "01001001011011101100",
> "1001001011010101",
> "1101110100000011",
> "000100100101001001011001",
> "000101101101101001101001")
>>
> 
> On Tue, May 26, 2009 at 12:30 PM, peng chen 
> wrote:
>> Hi, R experts:
>>
>> I am trying to generate data output in the following format:
>>
>> rom_array := (
>> "",
>> "01001001011011101100",
>> "1001001011010101",
>> "1101110100000011",
>> "000100100101001001011001",
>> "000101101101101001101001")
>>
>> I have all the necessary data line, however, I am having trouble
>> generating
>> the double quotation marks along with the trailing comma for each line.
>>
>> Anyone can help?
>>
>> Thanks.
>>
>>        [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Help-needed-on-R-output-tp23716736p23720449.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] how to implement a circular buffer with R

2009-05-24 Thread Adrian Dusa

Still not elegant, but I would split the string first:
spl.str <- unlist(strsplit("12345abcdefgh12345abcdefgh", ""))

Measure its length:
len.str <- length(spl.str)

Shift it:
spl.str <- c(spl.str[len.str], spl.str[seq(len.str - 1)])

Then paste it back together:
paste(spl.str, collapse="")  # "h12345abcdefgh12345abcdefg"

Shift it again (same command):
spl.str <- c(spl.str[len.str], spl.str[seq(len.str - 1)])

Paste it again (same command):
paste(spl.str, collapse="")  # "gh12345abcdefgh12345abcdef"

And so on.

Hth,
Adrian


milton ruser wrote:
> 
> Hi Maura,
> 
> It is not "elegant" but may work.
> 
> 
> actual.string<- "12345abcdefgh12345abcdefgh"
> actual.string
> actual.string<-paste(substr(actual.string,
> nchar(actual.string),nchar(actual.string)),
>substr(actual.string, 1,nchar(actual.string)-1), sep="")
> actual.string
> 
> 
> #in a looping
> 
> actual.string<- "12345abcdefgh12345abcdefgh"
> number.buffers<-10
> my.buffers<-actual.string
> for (i in 1:number.buffers)
>  {
>  actual.string<-paste(substr(actual.string,
> nchar(actual.string),nchar(actual.string)),
>substr(actual.string, 1,nchar(actual.string)-1), sep="")
>  my.buffers<-c(my.buffers, actual.string)
>  }
> my.buffers
> 
> Ciao,
> 
> milton
> brazil=toronto
> On Sun, May 24, 2009 at 1:09 PM,  wrote:
> 
>> Some wavelet analysis experts have implemented periodic boundary
>> conditions
>> for signals.
>> I need to implement a circular buffer. Something like:
>> "12345abcdefgh12345abcdefgh"
>>  so that at each step the riightmost element is moved to the leftmost
>> index
>> and everything else is properly shifted:
>> "h12345abcdefgh12345abcdefg", "gh12345abcdefgh12345abcdef", 
>>
>> My implementation (still debugging) seems to start working but is
>> terribly
>> clumsy.
>> I am sure that some expert can suggest a more elegant solution,
>> Thank you.
>> Maura
>>
>>
>>
>> tutti i telefonini TIM!
>>
>>
>>[[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/how-to-implement-a-circular-buffer-with-R-tp23695934p23696838.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Row number of minimum value?

2009-05-17 Thread Adrian Dusa
Hi Mike,

On Sunday 17 May 2009, MikSmith wrote:
> Hi
>
> This *must* be an insanely easy thing to work out, but I'm not too familiar
> with R syntax. So how do I work out the row number (if I pass a column) of
> the minimum value?? I can get the value itself from min(), but where can I
> get the row??

Maybe this helps:
which(mycol == min(mycol))

where "mycol" is your column.
Hth,
Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391

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


Re: [R] split a character variable into several charac ter variable by a character

2009-04-10 Thread Adrian Dusa
Good observation, Bill!
Adrian

On Friday 10 April 2009, William Dunlap wrote:
> strsplit() is the way to do it, but if your putative
> character strings come from a data.frame you need to make
> sure they are really character strings and not factors
> (at least in R 2.8.1).
>
>> d<-data.frame(name=c("Bill Dunlap", "First Last"), num=1:2)
>> d
>
> name num
>1 Bill Dunlap   1
>2  First Last   2
>
>> sapply(d,class)
>
> name   num
>"factor" "integer"
>
>> strsplit(d$name, " ")
>
>Error in strsplit(d$name, " ") : non-character argument
>
>> strsplit(as.character(d$name), " ")
>
>[[1]]
>[1] "Bill"   "Dunlap"
>
>[[2]]
>[1] "First" "Last"
>
>> d1<-data.frame(stringsAsFactors=FALSE,name=c("Bill Dunlap", "First
>
> Last"), num=1:2)
>
>> sapply(d1,class)
>
>   name num
>"character"   "integer"
>
>> strsplit(d1$name, " ")
>
>[[1]]
>[1] "Bill"   "Dunlap"
>
>[[2]]
>[1] "First" "Last"
>
> Bill Dunlap
> TIBCO Software Inc - Spotfire Division
> wdunlap tibco.com
>
> 
> -
> [R] split a character variable into several character variableby a
> character
>
> Adrian Dusa dusa.adrian at gmail.com
> Fri Apr 10 15:48:53 CEST 2009
>
> Dear Mao Jianfeng,
>
> "r-help-owner" is not the place for help, but:
> r-help at r-project.org
> (CC-ed here)
>
> In any case, strsplit() does the job, i.e.:
> > unlist(strsplit("BCPy01-01", "-"))
>
> [1] "BCPy01" "01"
>
> You can work with the whole variable, like:
> splitpop <- strsplit(df1$popcode, "-")
>
> then access the first part with
>
> > unlist(lapply(splitpop, "[", 1))
>
>  [1] "BCPy01" "BCPy01" "BCPy01" "BCPy01" "BCPy01" "BCPy01" "BCPy01"
> "BCPy01"
>  [9] "BCPy01" "BCPy01"
>
> and the second part with
>
> > unlist(lapply(splitpop, "[", 2))
>
>  [1] "01" "01" "01" "02" "02" "02" "02" "02" "02" "03"
>
> hth,
> Adrian
>
> On Friday 10 April 2009, Mao Jianfeng wrote:
> > Dear, R-lister,
> >
> > I have a dataframe like the followed. And, I want to split a character
> > variable ("popcode", or "codetot") into several new variables. For
>
> example,
>
> > split "BCPy01-01" (popcode[1]) into "BCPy01" and "01". I need to know
>
> how
>
> > to do that. I have tried strsplit() and substring() functions. But, I
>
> still
>
> > can not perform the spliting.
>
> It always helps to see exactly what you tried
> and a description of how the results differ from
> what you wanted to get.
>
> > Any advice? Thanks in advance.
> >
> > df1:
> > popcode codetot   p3need
> > BCPy01-01 BCPy01-01-1 100.
> > BCPy01-01 BCPy01-01-2 100.
> > BCPy01-01 BCPy01-01-3 100.
> > BCPy01-02 BCPy01-02-1  92.5926
> > BCPy01-02 BCPy01-02-1 100.
> > BCPy01-02 BCPy01-02-2  92.5926
> > BCPy01-02 BCPy01-02-2 100.
> > BCPy01-02 BCPy01-02-3  92.5926
> > BCPy01-02 BCPy01-02-3 100.
> > BCPy01-03 BCPy01-03-1 100.
> >
> > Regards,
> >
> > Mao Jian-feng


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391

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


Re: [R] split a character variable into several character variable by a character

2009-04-10 Thread Adrian Dusa
Dear Mao Jianfeng,

"r-help-owner" is not the place for help, but:
r-help@r-project.org
(CC-ed here)
In any case, strsplit() does the job, i.e.:

> unlist(strsplit("BCPy01-01", "-"))
[1] "BCPy01" "01"

You can work with the whole variable, like:
splitpop <- strsplit(df1$popcode, "-")

then access the first part with
> unlist(lapply(splitpop, "[", 1))
 [1] "BCPy01" "BCPy01" "BCPy01" "BCPy01" "BCPy01" "BCPy01" "BCPy01" "BCPy01"
 [9] "BCPy01" "BCPy01"

and the second part with
> unlist(lapply(splitpop, "[", 2))
 [1] "01" "01" "01" "02" "02" "02" "02" "02" "02" "03"

hth,
Adrian

On Friday 10 April 2009, Mao Jianfeng wrote:
> Dear, R-lister,
>
> I have a dataframe like the followed. And, I want to split a character
> variable ("popcode", or "codetot") into several new variables. For example,
> split "BCPy01-01" (popcode[1]) into "BCPy01" and "01". I need to know how
> to do that. I have tried strsplit() and substring() functions. But, I still
> can not perform the spliting.
>
> Any advice? Thanks in advance.
>
> df1:
> popcode codetot   p3need
> BCPy01-01 BCPy01-01-1 100.
> BCPy01-01 BCPy01-01-2 100.
> BCPy01-01 BCPy01-01-3 100.
> BCPy01-02 BCPy01-02-1  92.5926
> BCPy01-02 BCPy01-02-1 100.
> BCPy01-02 BCPy01-02-2  92.5926
> BCPy01-02 BCPy01-02-2 100.
> BCPy01-02 BCPy01-02-3  92.5926
> BCPy01-02 BCPy01-02-3 100.
> BCPy01-03 BCPy01-03-1 100.
>
> Regards,
>
> Mao Jian-feng


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391

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


Re: [R] Random sampling based on the observations

2009-03-24 Thread Adrian Dusa
On Tuesday 24 March 2009, you wrote:
> Hello!I am having a problem with Random sampling in R. I have used a
> syntax: mydata.sub=sample(mydata,7,replace=FALSE,prob=NULL) which allows me
> to choose a random sample based on the variables(correct me if I am
> wrong!).

Actually, no.
You are sampling from a vector, and where you're using the sampled values (on 
the rows or on the variables) is up to you.

Let's say we have a dataset with 100 cases and 10 variables:

Case 1:
mydata.sub <- mydata[ , sample(10, 7)]

This will sample 7 variables out of 10.

Case 2:
mydata.sub <- mydata[sample(100, 10), ]

This will sample 10 cases out of 100.

> Suppose I have 10 variable and if I use the above mentioned
> command then it will choose 7 variables out of the 10 randomly. My problem
> is that I want to have a random sample which is not based on the variables
> but on the values of the variables that is the random sample will be based
> on the observations. It will be great if someone can help me out me out with
> a proper syntax. Thanks in Advance.

I think you need to read the help for:
?"["

and most probably one of the introductory books for R.
I hope this helps,
Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391


[[alternative HTML version deleted]]

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


Re: [R] How to write a function that accepts unlimited number of input arguments?

2009-03-10 Thread Adrian Dusa

I might very well be wrong, but something tells me Sean really wants:
sum(1:5)

or (more close to the kind of unlimited number of arguments):
sum(c(1,2,3,4,5,17))

But then again, I might be mistaken.
Best wishes,
Adrian

On Monday 09 March 2009, Gabor Grothendieck wrote:
> Try this:
>
> sum.test <- function(...) sum(c(...))
>
> More commonly one uses the list(...) construct.
>
> On Mon, Mar 9, 2009 at 11:32 AM, Sean Zhang  wrote:
> > Dear R-helpers:
> > I am an R newbie and have a question related to writing functions that
> > accept unlimited number of input arguments.
> > (I tried to peek into functions such as paste and cbind, but failed, I
> > cannot see their codes..)
> >
> > Can someone kindly show me through a summation example?
> > Say, we have input scalar,  1 2 3 4 5
> > then the ideal function, say sum.test, can do
> > (1+2+3+4+5)==sum.test(1,2,3,4,5)
> >
> > Also sum.test can work as the number of input scalar changes.
> >
> > Many thanks in advance!



-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391


[[alternative HTML version deleted]]

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


Re: [R] Dropping rows conditionally

2009-03-04 Thread Adrian Dusa
Hi Lazarus,
It would be more simple with mdat as a matrix (before coercing to a 
data.frame). It might be a simpler way to compare a matrix with a vector but I 
don't find it for the moment; in any case, this works:
mdatT <- matrix(mdat %in% c(1, 11, 20), ncol=3)
> mdat[!apply(mdatT, 1, any), ]
 C.1 C.2 C.3
row2   4   5   6
row3   7   8   9
row5  13  14  15
row6  16  17  18
Or you can use apply directly on a data.frame, with the same result:
mdat <- as.data.frame(mdat)
> mdat[!apply(mdat, 1, function(x) any(x %in% c(1, 11, 20))), ]
 C.1 C.2 C.3
row2   4   5   6
row3   7   8   9
row5  13  14  15
row6  16  17  18

hth,
Adrian

On Thursday 05 March 2009, Lazarus Mramba wrote:
> Dear R-help team,
>
> I am getting addicted to using R but keep on getting many challenges on the
> way especially on data management (data cleaning).
>
> I have been wanting to drop all the rows if there values are  `NA' or have
> specific values like 1 or 2 or 3.
>
>
> mdat <- matrix(1:21, nrow = 7, ncol=3, byrow=TRUE,
>dimnames = list(c("row1",
> "row2","row3","row4","row5","row6","row7"), c("C.1", "C.2", "C.3")))
> mdat<-data.frame(mdat)
> mdat
>
>   C.1 C.2 C.3
> row1   1   2   3
> row2   4   5   6
> row3   7   8   9
> row4  10  11  12
> row5  13  14  15
> row6  16  17  18
> row7  19  20  21
>
> I want to say drop row if value=1 or value =11 or value =20
>
> How do I do that?
>
>
> Kind regards,
> Lazarus Mramba


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391


[[alternative HTML version deleted]]

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


Re: [R] [R-pkgs] New package: exams - Automatic Generation of Standardized Exams

2009-02-23 Thread Adrian Dusa

Dear Bertina,

This is an interesting solutions to generate unique tests for every student, 
and there are also some more possible approaches.
We also faced this problem and our solution was to adopt the Moodle e-learning 
platform (http://www.moodle.org), create a large pool of exercises and each 
student would then get a unique test, with randomly selected questions.

What I am dreaming of (in the long term), is to link R to Moodle to 
automatically generate questions and answers, in the very same approach 
adopted at TU Wien but not with printed PDF files but directly on the server.

The big advantage is the automatic correction of the tests, with no need of 
OCR reading or manually grading, all in a nice MySQL database. Of course, this 
means that exams are given in the computer lab, but since the tests are unique 
we do that over the course of multiple consecutive days.

Useful package nevertheless, thanks very much!
Adrian

On Monday 23 February 2009, Bettina Gruen wrote:
> Dear useRs,
>
> the new R package exams provides Sweave-based automatic generation of
> exams with multiple-choice questions and arithmetic problems. The
> package is available from CRAN:
>
> http://CRAN.R-project.org/package=exams
>
> It includes a vignette giving an overview of the main design aims and
> principles as well as strategies for adaptation and extension.
> Hands-on illustrations - based on example exercises and control files
> provided in the package - are presented to get new users started easily.
>
> Best,
> Bettina
>
> ___
> R-packages mailing list
> r-packa...@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-packages


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391


[[alternative HTML version deleted]]

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

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


Re: [R] sas.get under Linux

2009-02-03 Thread Adrian Dusa
On Monday 02 February 2009, Frank E Harrell Jr wrote:
> > [...]
>
> Stat/Transfer has a menu option to read the SAS format catalog but I
> haven't tried it.

Been there, done that... didn't get the t-shirt though.
I tried everything I believe, but with no avail.

Thanks again,
Adrian

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391


[[alternative HTML version deleted]]

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


Re: [R] sas.get under Linux

2009-02-02 Thread Adrian Dusa
Dear Ayah,

On Saturday 31 January 2009, Ajay ohri wrote:
> Hi,
> have you looked at the third party SAS language compilers WPS ( 600 dollars
> per desktop version http://www.teamwpc.co.uk/home/ ) and Carolina (
> http://dullesopen.com/)  <http://dullesopen.com/>
> <http://dullesopen.com/>
> if you need just base SAS.

Acually... no. I don't plan to use SAS in the future (I use R! :), just need 
it for the moment to extract some value labels.
Best wishes,
Adrian

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391


[[alternative HTML version deleted]]

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


Re: [R] sas.get under Linux

2009-02-02 Thread Adrian Dusa
Dear Frank,

I understand. Never used SAS before, so I don't have it installed anywhere.
StatTransfer is a very useful tool indeed, but maybe I don't know how to use 
it properly.
What I have is a "mydata.sas7bdat" file, along with a "formats.sas7bcat" file. 
I specified  reading SAS value labels "Read directly from a catalog file", but 
nothing appears in the output, neither in the R workspace nor in an 
intermediate SPSS file.
I also tried exporting to a SAS portable file to import directly in R, but 
there is probably something obvious that I miss because value labels are not 
there, whatever I do...

Thanks for your help,
Adrian

On Saturday 31 January 2009, Frank E Harrell Jr wrote:
> Adrian Dusa wrote:
> > Dear all,
> >
> > I am trying to import a SAS file into R (in fact I only need the value
> > labels from the formats file), using Hmisc package, but I get this error:
> >
> > my.sas <- sas.get("/home/adi/3", "fis1_sgg")
> > sh: sas: not found
> > Error in sas.get("/home/adi/3", "fis1_sgg") :
> >   SAS job failed with status 32512
> >
> > I read some past discussions and I get the impression that sas.get()
> > needs the full path to the SAS executable, but I don't have that because
> > I am using Linux.
> >
> > Is it possible to use sas.get() without having SAS installed?
>
> Since sas.get is trying to execute sas the answer is a definite no
> unless you use the sas.get option to run SAS on another machine to
> produce the input ASCII files needed by sas.get.  Also investigate
> sasxport.get if you have SAS version 5 transport files to import.
> See also http://biostat.mc.vanderbilt.edu/SASexportHowto
>
> As SAS never got it right in allowing for full metadata to be included
> in a SAS dataset, you often have to run PROC FORMAT CNTLOUT=... to
> convert format libraries to SAS datasets so that programs such as
> sasxport.get can assign value labels [if you have SAS installed, sas.get
> runs PROC CONTENTS for you.].  SPSS and Stata have always been ahead of
> SAS in this regard.
>
> Note that the excellent Stat/Transfer commercial product will convert
> from almost any SAS dataset format to compact R binary objects,
> including variable labels the way the Hmisc package handles them.  If
> you have another way to convert from SAS to Stata or SPSS, R is great at
> readying those formats.
>
> Frank
>
> > Or alternatively, is there another function to import the formats into R?
> >
> > Thanks in advance for any hint,
> > Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391


[[alternative HTML version deleted]]

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


[R] sas.get under Linux

2009-01-31 Thread Adrian Dusa
Dear all,

I am trying to import a SAS file into R (in fact I only need the value labels 
from the formats file), using Hmisc package, but I get this error:

my.sas <- sas.get("/home/adi/3", "fis1_sgg")
sh: sas: not found
Error in sas.get("/home/adi/3", "fis1_sgg") :
  SAS job failed with status 32512

I read some past discussions and I get the impression that sas.get() needs the 
full path to the SAS executable, but I don't have that because I am using 
Linux.

Is it possible to use sas.get() without having SAS installed?

Or alternatively, is there another function to import the formats into R?

Thanks in advance for any hint,
Adrian

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391


[[alternative HTML version deleted]]

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


Re: [R] QCA adn Fuzzy

2008-12-23 Thread Adrian Dusa
Hi ronggui,

I believe it is "dear Adrian and Prof. Gott" :)
(at least I feel more comfortable being called directly)

Thanks very much for this, I am developing a series of functions for fuzzy-set 
operations to be included in the next release of the QCA package, and your 
function seems to do a good job.

I am not currently at my office (away for the Christmas holiday), but I will 
of course resume my work once I get back in Bucharest.

In the mean time, I wish you all a Merry Christmas and lots of achievements in 
the new year.
Warm regards,
Adrian

On Tuesday 23 December 2008, ronggui wrote:
> Dear  Gott and Prof Adrian DUSA ,
>
> I am learning fuzzy set QCA and recently, I just write a function to
> construct a truthTable, which can be passed to QCA:::eqmcc to do the
> Boolean minimization.  The function is here:
> http://code.google.com/p/asrr/source/browse/trunk/R/fs_truthTable.R
> and the help page is:
> http://code.google.com/p/asrr/source/browse/trunk/man/fs_truthTable.rd
> and the example dataset  from Ragin (2009) is here
> http://code.google.com/p/asrr/source/browse/trunk/data/Lipset_fs.rda
>
> Best
>
> On Wed, Mar 8, 2006 at 2:13 AM, Adrian DUSA  wrote:
> > Dear Prof. Gott,
> >
> > On Monday 06 March 2006 14:37, R Gott wrote:
> >> Does anybody know of aything that will help me do Quantitiative
> >> Comparative Analysis (QCA) and/or Fuzzy set analysis??  Or failing that
> >> Quine?
> >> ta
> >> rg
> >> Prof R Gott
> >> Durham Univesrity
> >> UK
> >
> > There is a package called QCA which (in its first release) performs only
> > crisp set analysis. I am currently adapting a Graphical User Interface,
> > but the functions are nevertheless usefull.
> > For fuzzy set analysis, please consider Charles Ragin's web site
> > http://www.u.arizona.edu/%7Ecragin/fsQCA/index.shtml
> > which offers a software (still not complete, though). Also to consider
> > is a good software called Tosmana (http://www.tosmana.org/) which does
> > multi-value
> > QCA.
> > I am considering writing the inclusion algorithms in the next releases of
> >  my package, but it is going to take a little while. Any contributions
> > and/or feedback are more than welcome.
> >
> > I hope this helps you,
> > Adrian
> >
> >
> > --
> > Adrian DUSA
> > Romanian Social Data Archive
> > 1, Schitu Magureanu Bd
> > 050025 Bucharest sector 5
> > Romania
> > Tel./Fax: +40 21 3126618 \
> >  +40 21 3120210 / int.101
> >
> > __
> > r-h...@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391


[[alternative HTML version deleted]]

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


Re: [R] sliding window over a large vector

2008-12-16 Thread Adrian Dusa
Hi Chris,

On Tuesday 16 December 2008, Chris Oldmeadow wrote:
> Hi all,
>
> I have a very large binary vector, I wish to calculate the number of
> 1's  over sliding windows.
> [...snip...]

Your function does not seem to function very well, could you please offer a 
self-contained, reproducible example?

When writing a function, it is indicated not to use reserved commands like 
"seq" (which is a function itself, generating a sequence of numbers).

In any case, I suspect you might want to take a look on the function "rle".
See ?rle

I hope this helps,
Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391


[[alternative HTML version deleted]]

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


[R] SPSSyntax function

2008-11-26 Thread Adrian Dusa
Dear all,

I've created a function called "spssyntax" that creates a syntax for
variable labels and value labels in SPSS (in the *sps* syntax format
that was recently discussed), using a list of such labels in R.
The entry list looks like this (between the ### signs):

###
labels <- list()

labels$varlab$id <- "ID"
labels$varlab$v1 <- "A label for the first variable"

labels$vallab$v1 <- c(
"Very low"=1,
"Low"=2,
"Middle"=3,
"High"=4,
"Very high"=5,
"Not Applicable"=-1,
"Not Answered"=-2)
###


And the result syntax file looks like this (again, between the ### signs):

###
VARIABLE LABELS
id "ID"
v1 "A label for the first variable"
.

VALUE LABELS
v1
1 "Very low"
2 "Low"
3 "Middle"
4 "High"
5 "Very high"
-1 "Not Applicable"
-2 "Not Answered"
/
.

MISSING VALUES
v1 (-1, -2)
.
###

Should there be any package interested in adopting this function
(maybe foreign?), I'd be happy to contribute it.
Best regards,
Adrian

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


Re: [R] [R-pkgs] RQDA-0.1.5 is released

2008-11-25 Thread Adrian Dusa
Hi ronggui,

I tried to install your package under linux (Kubuntu Intrepid), but the 
depending package RGtk2 does not install under Linux, some kind of an error

Warning message:
In install.packages(c("DBI", "RSQLite", "RGtk2", "gWidgets", "gWidgetsRGtk2")) 
  installation of package 'RGtk2' had non-zero exit status

You're saying RQDA can be used under Linux, but can it work without RGtk2?
Thanks,
Adrian


On Monday 24 November 2008, ronggui wrote:
> RDQA is a package for Qualitative Data Analysis built upon R. It works
> both on the Windows and Linux/FreeBSD platforms. RQDA is an
> easy-to-use tool to assist in the analysis of textual data. At the
> present, it supports only plain text format data. All the information
> is stored in SQLite database via the R package of RSQLite. The GUI is
> based on RGtk2, via the aid of gWidgetsRGtk2. It includes a number of
> standard Computer-Aided Qualitative Data Analysis features. Besides,
> it seamlessly integrated with R, which means that a) statistical
> analysis on the coding is possible, and b) functions about data
> manipulation and analysis can be easily extended by writing R
> functions. To some extent, RQDA and R makes an integrated platform for
> both quantitative and qualitative data analysis.
>
> The current version should be regarded as Release Candidate Version, I
> will test it preliminary under Chinese Windows  OS, but it should work
> under Linux and FreeBSD.
>
> By the GUI, it can:
> # Import documents from plain text
> # Support non-English documents, Simplified Chinese Character is
> well-tested under Windows
> # Character-level coding using codes
> # Memos of documents, codes, coding, project, files and more
> # Retrieval of coding
> # Single-file (*.rqda) format, which is basically SQLite database.
> Data are stored in UTF-8, so it should be portable
> # Facilitator helps to categorize codes,which is key to theory
> building. I deliberately avoid using tree-like categorization
> # There is a case category, which is crucial feature to bridge
> qualitative and quantative research
> # Search information about selected case from the Internet vis popup menu
> # Temporary delete files and codes
> # Rename the files,code, code category, case and others
>
> More information can be found in http://rqda.r-forge.r-project.org/
>
> Comments and suggestions are welcome:)


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391


[[alternative HTML version deleted]]

___
R-packages mailing list
[EMAIL PROTECTED]
https://stat.ethz.ch/mailman/listinfo/r-packages

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


Re: [R] remove levels from a factor

2008-08-30 Thread Adrian Dusa
Adrian Dusa  gmail.com> writes:
> > [...snip...]
> > f[which(f %in% names(table(f))[table(f) >= 2]), drop=TRUE]
> [1] a a
> Levels: a

Or, more simple:

> f[f %in% names(table(f))[table(f) >= 2], drop=TRUE]
[1] a a
Levels: a

Adrian

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


Re: [R] remove levels from a factor

2008-08-30 Thread Adrian Dusa

Yuan Jian  yahoo.com> writes:

> [...snip...]
> 
> I want to remove level b because level b has less than 2.
> > f
> [1] a a
> Levels: a


> f[which(f %in% names(table(f))[table(f) >= 2]), drop=TRUE]
[1] a a
Levels: a

HTH,
Adrian

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


Re: [R] How to repress the annoying complains from X window system

2008-08-12 Thread Adrian Dusa
On Tuesday 12 August 2008, Prof Brian Ripley wrote:
> On Tue, 12 Aug 2008, John Fox wrote:
> > Dear Mark and Adrian,
> >
> > I was under the impression that these errors were fixed in R 2.4.0; you
> > could try setting the Rcmdr option suppress.X11.warnings=TRUE and see
> > whether that helps (but first read the information on the option in
> > ?Commander).
>
> The X11() warnings were fixed in 2.4.0: at least one of the messages here
> is from Tk, which also makes use of X11.  The processing of the Rcmdr
> option would need to be expanded to catch the Tk version of the message
> shown.
>
> I've never been able to reproduce these messages, so can't help track them
> down.

Thank you all for your replies.
Actually, I am not able to reproduce them myself...!
I tried to push it in different ways and different options, just to catch them 
but they seem to have vanished. Really sorry I can't offer more information, 
but I will try to keep a more detailed log of my actions and if I do stumble 
upon them I will report back.

In the mean time, enjoy useR.
Best wishes,
Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391


signature.asc
Description: This is a digitally signed message part.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to repress the annoying complains from X window system

2008-08-11 Thread Adrian Dusa
On Monday 11 August 2008, Patrick Connolly wrote:
> On Sat, 09-Aug-2008 at 04:06PM -0700, dusa.adrian wrote:
>
> [...]
>
> |> Warning in structure(.External("dotTclObjv", objv, PACKAGE = "tcltk"),
> |> class = "tclObj") :
> |>   X11 protocol error: BadWindow (invalid Window parameter)
> |>
> |> > R.version
> |>
> |>_
> |> platform   i486-pc-linux-gnu
> |> arch   i486
>
> Is that a pre-Pentium machine??

Nope, quite the contrary. It's a HP mobile workstation model 8710w, with a 
Intel Core2Duo processor at 2.6 GHz and 2GB of RAM...

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391


signature.asc
Description: This is a digitally signed message part.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Change language in Rcmdr

2008-07-08 Thread Adrian Dusa
On Monday 07 July 2008, Philippe Grosjean wrote:
> Hello,
>
> As far as I know, Rcmdr is already translated in French. It is thus just
> a question of switching R to French.

Alternatively, you could switch the language after R starts:

Sys.putenv(LANGUAGE="fr")

After this, Rcmdr will be opened in French.
Best,
Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
 +40 21 3120210 / int.101
Fax: +40 21 3158391


signature.asc
Description: This is a digitally signed message part.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Subsetting to unique values

2008-06-06 Thread Adrian Dusa
Emslie, Paul [Ctr]  atac.mil> writes:

> 
> I want to take the first row of each unique ID value from a data frame.
> For instance
> > ddTable <-
> data.frame(Id=c(1,1,2,2),name=c("Paul","Joe","Bob","Larry"))
> 
> I want a dataset that is 
> IdName
> 1 Paul
> 2 Bob
> 
> > unique(ddTable)
> Will give me all 4 rows, and
> > unique(ddTable$Id) 
> Will give me c(1,2), but not accompanied by the name column.


ddTable[-which(duplicated(ddTable$Id)), ]

HTH,
Adrian

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


Re: [R] best text editor for Linux?

2008-02-03 Thread Adrian Dusa
On Saturday 02 February 2008, Frank E Harrell Jr wrote:
> Stefan Grosse wrote:
> [...]
> > alternatively you could use the hardy (next ubuntu version) repository
> > either via synaptic or the package (for the 0.4.9 package):
> >
> > http://packages.ubuntu.com/hardy/math/rkward
>
> The hardy release has major dependency problems for gutsy users.
>
> So there is no version of rkward that is made for Ubuntu gutsy for users
> with current versions or R.

I'm using Gutsy and managed to install rkward. It does have some dependencies 
which need some upgrades, but it wasn't such a hassle.

The only package it really complained was libgfortran, but I found this fix on 
the Internet:

sudo ln -s /usr/lib/libgfortran.so.2 /usr/lib/libgfortran.so

After that, it worked like a charm and must say I'm pretty impressed. It they 
keep developing it like that, I might actually switch (for the moment I use 
the good old jEdit).

Hope it helps,
Adrian

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101


signature.asc
Description: This is a digitally signed message part.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Trouble receiving messages from the mailing list

2008-01-18 Thread Adrian Dusa
On Friday 18 January 2008, Ted Harding wrote:
> [...]
>
> This policy would carry a risk that spam mail "From:" a
> subscribed address (probably with a forged "From:", but
> possibly also from a subscriber's compromised computer)
> will reach the list. But I dare say the rest of us can
> live with that. I certainly could.

One possible solution is to digitally sign the message, but there are probably 
few people who know about PGP and its benefits...

Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101


signature.asc
Description: This is a digitally signed message part.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] connecting [logging] RMySQL to an external server - SOLVED

2007-12-19 Thread Adrian Dusa
Hi James,

On Wednesday 19 December 2007, David James wrote:
> Hi,
>
> I'm sorry I'm also coming late to this discussion, but  like Dirk, I
> fail to understand what's wrong with using dbConnect() the way
> the documentation, (see ?MySQL) suggests.
>
> RMySQL was developed in a fully distributed client/server
> environment, and it uses the MySQL-provided client API.  The
> options that the MySQL client library allows (user, password, host,
> port or socket file, compression, etc.) should work from RMySQL
> (RMySQL just passes those directly to the MySQL client library).
> If you have a specific (e.g., security-related) need that the MySQL client
> API does not address, then the use of ssh may be the proper way
> to go.  But for simple, vanilla style of client-server communications
> the underlying MySQL client should be sufficient.

Normally yes, you are right, but this particular MySQL server does not allow 
remote connections (it does not directly listens to port 3306) but only local 
connections using a socket (this terminology is unfamiliar to me, I may talk 
stupid).
So I have to first create a secure login and only after that connect to the 
remote MySQL server.

I hope my situation is more clear now,
Adrian



-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


Re: [R] connecting [logging] RMySQL to an external server - SOLVED

2007-12-19 Thread Adrian Dusa
On Wednesday 19 December 2007, Dirk Eddelbuettel wrote:
> [...]
>
> Err, I am late to this but
>
>  dbConnect(drv, user="mysqluser", password="mysqlpassword",
> dbname="anydatabase", host="xxx.xxx.xxx")
>
> works fine for me (eg on Ubuntu with a remote MySQL on some other
> box).  What's the problem you were seeing?

The remote host expects a login username and password (different from the 
MySQL username and password), which I cannot provide in the dbConnect 
function.
The solution is to first login to the external machine (a secure login using 
ssh), forwarding the MySQL port 3306 to the local port 3307 (not to interfere 
with the local MySQL server), and connecting R to the remote MySQL server 
using the ssh tunneling binded to local port 3307.

Best,
Adi


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


Re: [R] connecting [logging] RMySQL to an external server - SOLVED

2007-12-19 Thread Adrian Dusa
On Saturday 15 December 2007, Gabor Grothendieck wrote:
> Use ssh forwarding to forward local port 3307 to remote port 3306
> specifying the remote account and password.  Then if you use local port
> 3306 you can access your local version of MySQL and if you
> use port 3307 you can access the remote version.   There is some
> info on the MySQL site.  First test it out by running the mysql command
> line program accessing the remote data base via port 3307 and once
> that works you know its ok and you can try RMySQL or RODBC packages.

For those interested in using R with a remote MySQL database, here's the most 
simple and straightforward solution (thanks to Gabor):

On the console, forward local port 3307 to remote port 3306
ssh -L 3307:xxx.xxx.xxx.xxx:3306 [EMAIL PROTECTED]

(where xxx.xxx.xxx.xxx is the IP of the remote server and myuser is the login 
name). After entering the password, keep that console open.

In R:

library(RMySQL)
drv <- dbDriver("MySQL")
dbConnect(drv, user="mysqluser", password="mysqlpassword", 
dbname="anydatabase", host="127.0.0.1", port="3307")

(where mysqluser and mysqlpassword are the remote machine's MySQL username and 
password).

Another possible solution is suggested by Prof. Ripley, using stunnel to 
create a secure tunnel between the local and the remote machines, but I 
haven't explored that in detail.


Best wishes,
Adrian

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


Re: [R] read.table and double quotes in strings

2007-12-16 Thread Adrian Dusa
On Sunday 16 December 2007, Adrian Dusa wrote:
> Dear all,
>
> [...]
>
> Given these examples, I have two questions:
> 1. What is the correct syntax to import the R-exported file
> 2. What can I do to prevent these situations from happening?
> (besides whipping the data entry person :), I am referring to R procedures
> to detect and correct such things)

Trying to answer question number 2: would the usage of qmethod="double" 
argument in write.table solve the problem *in general*?

What are the situations that specifically need escaping the quote character?

Thank you,
Adrian



-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


[R] read.table and double quotes in strings

2007-12-16 Thread Adrian Dusa

Dear all,

Some very wise data entry person gave me about an hour of a headache, trying 
to find out why a 2000x500 dataframe won't be read into R.
After much trial and error, I pinpointed the problem to an accidentally 
inserted double quote into a string variable (some comments from an open 
question). This can be replicated by:

aa <- data.frame(id=1:2, var1=c("some \" quote", "without quote"))
> aa
  id  var1
1  1  some " quote
2  2 without quote

Saving this with R:
write.table(aa, "aa.dat", sep="\t", row.names=F)

creates the following ASCII file (between #s)

### R export
"id""var1"
1   "some \" quote"
2   "without quote"
###

which throws an error when trying to load it back:

> bb <- read.table("aa.dat", sep="\t", header=T)
Warning message:
In read.table("aa.dat", sep = "\t", header = T) :
  incomplete final line found by readTableHeader on 'aa.dat'

The dataframe was initially an SPSS file, which saved it as tab delimited in 
this format:

### SPSS export
"id""var1"
1   "some " quote"
2   "without quote"
###

which of course thrown the same obvious error.

StatTransfer was the only software that solved the problem of exporting the 
SPSS file in a tab delimited file that could finally be imported in R, and 
the saved file looks like this:

### StatTransfer export
"id""var1"
1   "some "" quote"
2   "without quote"
###

Given these examples, I have two questions:
1. What is the correct syntax to import the R-exported file
2. What can I do to prevent these situations from happening?
(besides whipping the data entry person :), I am referring to R procedures to 
detect and correct such things)

Thank you,
Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


Re: [R] connecting RMySQL to and external server

2007-12-15 Thread Adrian Dusa
On Saturday 15 December 2007, you wrote:
> Use ssh forwarding to forward local port 3307 to remote port 3306
> specifying the remote account and password.  Then if you use local port
> 3306 you can access your local version of MySQL and if you
> use port 3307 you can access the remote version.   There is some
> info on the MySQL site.  First test it out by running the mysql command
> line program accessing the remote data base via port 3307 and once
> that works you know its ok and you can try RMySQL or RODBC packages.

Thanks Gabor, it is a little bit of a foreign language for me (at the moment) 
but I'm sure your hints will be relevant to our sysadmin.
I do want to understand this stuff myself, just need more digging in the 
manuals.

Cheers,
Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
          +40 21 3120210 / int.101

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


Re: [R] connecting RMySQL to and external server

2007-12-15 Thread Adrian Dusa
On Saturday 15 December 2007, Prof Brian Ripley wrote:
> On Sat, 15 Dec 2007, Adrian Dusa wrote:
> > Indeed, I noticed the "host" argument but the server demands an username
> > and a password for the machine first,
>
> But you said 'connect to', not 'log in to', so how were we to know that?
>
> > and only after that for the MySQL server.
> > Those were the arguments I was looking for.
> > I will study the RODBC package then, if it solves the problem.
>
> I am afraid I don't understand your setup. MySQL works by listening on
> port 3306: user accounts don't come into that.  With our bastion servers
> all such ports are blocked and can only be accessed via tunnels
> (implemented by stunnel).  I think you need to discuss this with your
> sysadmins: if it works under mysql or for ODBC (isql) it will work with
> the corresponding R packages.

Of course, most definitely. I usually log in to the external machine using 
ssh, then access the MySQL server using the MySQL username and password.
I probably asked for too much from R, since logging to an external machine 
needs a secure connection.
I'll talk to our sysadmin for local advice, thanks again.

Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


Re: [R] connecting RMySQL to and external server

2007-12-15 Thread Adrian Dusa

Indeed, I noticed the "host" argument but the server demands an username and a 
password for the machine first, and only after that for the MySQL server. 
Those were the arguments I was looking for.
I will study the RODBC package then, if it solves the problem.

Thank you very much,
Adrian


On Saturday 15 December 2007, Prof Brian Ripley wrote:
> It is trivial with RODBC (I know that is not what you asked, but it is the
> solution we found first).
>
>
> For RMySQL, note first that the MySQL configuration file is consulted, so
> the default host is specified in the client section, which is like
>
> [client]
>
> port=3306
>
> [mysql]
>
> default-character-set=latin1
>
> Add host=foo under [client] to change the default host.
>
> And ?dbConnect mentions a 'host' argument under '...'.  That seems to work
> for me (provided of course the server allows connections from other
> machines): on my home network from Windows laptop to Linux server
>
> > library(RMySQL)
>
> Loading required package: DBI
>
> > drv <- dbDriver("MySQL")
> > con <- dbConnect(drv, user="ripley", host="auk", dbname="ripley")
>
> This mixture of using the *local* configuration file overridden by
> arguments is a bit dangerous: RMySQL seems not really designed for
> client-server operation and there are some things that definitely do not
> work.  (As I recall, that included dbWrite as that imports a file which is
> on the local machine.)
>
> On Fri, 14 Dec 2007, Adrian Dusa wrote:
> > Dear list,
> >
> > I learned how to connect R to a local MySQL server, using:
> > drv <- dbDriver("MySQL")
> > con <- dbConnect(drv, user="root", password="mypass", dbname="mydb")
> >
> > Is it possible to connect R in this way to an external server (on a
> > different machine, with a different IP)?
> >
> > I read the documentation on ?dbConnect (and everything I could find on
> > the internet), but I failed to find some other relevant arguments. For
> > example, one needs to first connect to the external machine and only
> > after that to the MySQL server on that machine. Is this possible from
> > within R?
> >
> > Thank you in advance,
> > Adrian



-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


[R] connecting RMySQL to and external server

2007-12-14 Thread Adrian Dusa

Dear list,

I learned how to connect R to a local MySQL server, using:
drv <- dbDriver("MySQL")
con <- dbConnect(drv, user="root", password="mypass", dbname="mydb")

Is it possible to connect R in this way to an external server (on a different 
machine, with a different IP)?

I read the documentation on ?dbConnect (and everything I could find on the 
internet), but I failed to find some other relevant arguments. For example, 
one needs to first connect to the external machine and only after that to the 
MySQL server on that machine. Is this possible from within R?

Thank you in advance,
Adrian

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


Re: [R] Dot plots in R

2007-11-26 Thread Adrian Dusa
On Saturday 24 November 2007, Paul Smith wrote:
> Dear All,
> Can R produce dot plots like the one of the following picture:
> http://en.wikipedia.org/wiki/Image:Dotplot_of_random_values.png
> ?
> I have tried dotchart, but no success.

I'm coming late to this thread, but I believe what Paul wants is better suited 
by the DOTplot() function from the UsingR package: it looks exactly the same 
as the web image and it has no axes, as Paul wants in a later message.

x <- sample(1:10, 30, replace=T)
library(UsingR)
DOTplot(x)

Hth,
Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


Re: [R] expand.grid overflows?

2007-11-18 Thread Adrian Dusa
On Friday 16 November 2007, francogrex wrote:
> >cbn<-as.matrix(expand.grid( rep( list(0:1), 50)))
>
> Error in rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) :
>   invalid 'times' value
> In addition: Warning message:
> In rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) :
>   NAs introduced by coercion
>
> But I'm only interested in cbn matrix rows where:
> cbn<- cbn[rowSums(cbn)==5,]
>
> Is there a way to evaluate it row by row and only store where the sum is
> equal to 5, maybe it reduces cost of computation?

What you want is impossible: a matrix with all possible binary combinations of 
50 columns is a matrix with 2^50x50 elements, which is:

> 2^50*50
[1] 5.6295e+16

By comparison, a matrix with 20 columns requires a space of 160MB, with 21 
columns it needs approx. 330MB of RAM (see ?object.size) and everything goes 
up exponentially at the powers of 2. There is simply no way you will ever 
create a matrix with 50 columns.

There is a function in package QCA called createMatrix() that creates a 
numerical matrix faster than expand.grid()

library(QCA)
cbn <- createMatrix(rep(2, 20))

# then what you want is 
cbn <- cbn[rowSums(cbn) == 5, ]



For more than 20 variables it _is_ possible to get what you want sacrificing 
speed for a low memory consumption, this way:

library(QCA)
nofcolumns <- 25
cbn.rownos <- seq(2^nofcolumns) # generate the row numbers
eq5 <- sapply(cbn.rownos, function(x) {
return(sum(getRow(rep(2, nofcolumns), x)) == 5)
})

# this will be _very_ slow, as it checks each row number (in its binary
# equivalent, see ?getRow) if it's sum is equal to 5

# then what you want is:

cbn <- getRow(rep(2, nofcolumns), cbn.rownos[eq5])


I hope it helps,
Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


Re: [R] generate combination set

2007-11-16 Thread Adrian Dusa
Hi Haris,

On Thursday 15 November 2007, Charilaos Skiadas wrote:
> I must be missing something. What's wrong with:
>
> combn(set, 2)
>
> or if we must t(combn(set,2)), optionally with a function argument in
> the combn call if something is to be done with the pairs?
>
> So if you really wanted the outputs to be "AB","AC" etc, you would do:
>
> combn(set,2, paste, collapse="")

Indeed, you got the right solution even from yesterday. I get my emails in a 
digest mode, so if you don't reply to all (CC all the others including the 
list) your solution doesn't arrive in my Inbox but until the next day.

Best,
Adrian

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


Re: [R] generate combination set

2007-11-16 Thread Adrian Dusa
On Friday 16 November 2007, Peter Dalgaard wrote:
> [...]
>
> Or even (from someone who have known about combn for a while)
>
> > combn(LETTERS[1:7], 2, paste, collapse="")
>
>  [1] "AB" "AC" "AD" "AE" "AF" "AG" "BC" "BD" "BE" "BF" "BG" "CD" "CE"
> "CF" "CG"
> [16] "DE" "DF" "DG" "EF" "EG" "FG"

Chapeau...

Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


Re: [R] generate combination set

2007-11-15 Thread Adrian Dusa
Using your "set", wouldn't it be simpler like this?

t(apply(combn(7,2), 2, function(x) set[x]))

Hth,
Adrian

On Thursday 15 November 2007, [EMAIL PROTECTED] wrote:
> There are a number of packages that do this, but here is a simple
> function for choosing subsets:
>
> subsets <- function(n, r)  {
>   if(is.numeric(n) & length(n) == 1) v <- 1:n else {
> v <- n
> n <- length(v)
>   }
>   subs <- function(n, r, v)
> if(r <= 0) NULL else
> if(r >= n) matrix(v[1:n], nrow = 1) else
> rbind(cbind(v[1], subs(n - 1, r - 1, v[-1])),
>   subs(n - 1, r, v[-1]))
>   subs(n, r, v)
> }
>
> Here is an example of how to use it:
> > set <- LETTERS[1:7]
> > subsets(set, 2)
>
>   [,1] [,2]
>  [1,] "A"  "B"
>  [2,] "A"  "C"
>  [3,] "A"  "D"
>  [4,] "A"  "E"
>  [5,] "A"  "F"
>  [6,] "A"  "G"
>  [7,] "B"  "C"
>  [8,] "B"  "D"
>  [9,] "B"  "E"
> [10,] "B"  "F"
> [11,] "B"  "G"
> [12,] "C"  "D"
> [13,] "C"  "E"
> [14,] "C"  "F"
> [15,] "C"  "G"
> [16,] "D"  "E"
> [17,] "D"  "F"
> [18,] "D"  "G"
> [19,] "E"  "F"
> [20,] "E"  "G"
> [21,] "F"  "G"
>
>
> Bill Venables
> CSIRO Laboratories
> PO Box 120, Cleveland, 4163
> AUSTRALIA
> Office Phone (email preferred): +61 7 3826 7251
> Fax (if absolutely necessary):  +61 7 3826 7304
> Mobile: +61 4 8819 4402
> Home Phone: +61 7 3286 7700
> mailto:[EMAIL PROTECTED]
> http://www.cmis.csiro.au/bill.venables/
>
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> On Behalf Of [EMAIL PROTECTED]
> Sent: Thursday, 15 November 2007 2:51 PM
> To: r-help@r-project.org
> Subject: [R] generate combination set
>
> I have a set data={A,B,C,D,E,F,G}
> I want to choose 2 letter from 8 letters, i.e. generate the combination
> set
> for choose 2 letters from 8 letters.
> I want to get the liking:
> combination set={AB,AC,AD,}
> Does anyone konw how to do in R.
>
> thanks,
>
> Aimin
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


Re: [R] generate combination set

2007-11-15 Thread Adrian Dusa
On Thursday 15 November 2007, [EMAIL PROTECTED] wrote:
> Actually, (now that I know about combn), a better way is
>
> t(matrix(set[combn(7,2)], nrow = 2))

Indeed, or to avoid transposing:

matrix(set[combn(7,2)], ncol = 2, byrow=T)

Adrian

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


Re: [R] list matching

2007-10-07 Thread Adrian Dusa
On Sunday 07 October 2007, Gabor Grothendieck wrote:
> I thought the latest zoo fixes were on CRAN but perhaps they
> are not.   Try this:
>
> library(zoo)
> # next line loads latest version of merge.zoo (fixed in August)
> source("http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/*checkout*/
>pkg/R/merge.zoo.R?rev=361&root=zoo")
>
> as.vector(time(do.call(merge, c(lapply(aa, function(x) zoo(,x)), all =
> FALSE

Yeap, that fixes it.
Ah-haa, so all = FALSE is merge()s argument...
Neat :)
Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


Re: [R] list matching

2007-10-07 Thread Adrian Dusa
On Sunday 07 October 2007, you wrote:
> Perhaps its a version problem?  [...]
>
> > R.version.string # Vista
>
> [1] "R version 2.6.0 beta (2007-09-23 r42958)"
>
> > packageDescription("zoo")$Version
>
> [1] "1.3-2"

I don't know, everything is up to date here, too.
I'm using Kubuntu Linux and the latest versions of R and zoo:

> R.version.string
[1] "R version 2.6.0 (2007-10-03)"

> packageDescription("zoo")$Version
[1] "1.3-2"

Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


Re: [R] list matching

2007-10-06 Thread Adrian Dusa
On Sunday 07 October 2007, Gabor Grothendieck wrote:
> zoo's merge can do a multiway intersection.  We turn each component
> of aa into the times of a dataless zoo object (assuming the elements of
> each component are unique) and merge them together using all = FALSE
> which will only leave those points at times in all components.  Extracting
> the time and stripping off the names gives the result.
>
> library(zoo)
> as.vector(time(do.call(merge, c(lapply(aa, function(x) zoo(,x)), all =
> FALSE

Hi Gabor, it's always good to see clever solutions. Never thought about using 
time series to perform intersections :)

I can't reproduce your solution though:
Error in rval[[1]] : subscript out of bounds

The elements of each component are indeed unique; the argument all = FALSE 
intrigues me: which function should use it, zoo() or c() ?

The result of lapply() is a list; when performing c() over that list, the 
argument all = FALSE does nothing but to add another branch... hmm, I should 
really use more time series...

Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


Re: [R] list matching

2007-10-06 Thread Adrian Dusa
On Saturday 06 October 2007, Marc Schwartz wrote:
> [...]
>
> intersectList <- function(x)
> {
>   res <- table(unlist(sapply(x, unique)))
>   names(res[res == length(x)])
> }
>
>
> In the first line, I use unique() to ensure that if the same letter
> appears more than once in the same list element, it is not included in
> the result set in error, such as in 'L' here:
>
>
> L <- list(a = c("a", "b", "b"), b = c("d", "b", "a"), c = c("d", "a"))
>
> > L
>
> $a
> [1] "a" "b" "b"
>
> $b
> [1] "d" "b" "a"
>
> $c
> [1] "d" "a"
>
> So:
> > intersectList(aa)
>
> [1] "e"
>
> > intersectList(L)
>
> [1] "a"


Neat :o)

Of course, this was the right way to follow... in my particular case the 
elements are always unique but generally this is the best approach indeed.

Thanks Marc,
Adrian


-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


[R] list matching

2007-10-06 Thread Adrian Dusa

Dear list,

Given a list of elements like:
aa <- list(one=c("o", "n", "e"),
   tea=c("t", "e", "a"),
   thre=c("t", "h", "r", "e"))

Is there a function that returns the intersection between all?
Both match() and intersect() only deal with two arguments, but sometimes I 
have more.

Here, it should return "e" (or NA if none of the letters are common).

I have a solution to apply %in% multiple times (here two times, first between 
the first two and then between the result and the third) but... perhaps there 
is a better and quicker way.

Thanks in advance,
Adrian

--
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


Re: [R] Adding a table to a plot area

2007-09-24 Thread Adrian Dusa
Frank E Harrell Jr  vanderbilt.edu> writes:
> Judith Flores wrote:
> > Is there a command to insert a table into the plot
> > area other that using text?
> > 
> > Thank you.
> 
> To me the only completely satisfying approach is to use LaTeX and psfrag 
> in you want great alignment and other features.  A howto with R is at 
> http://biostat.mc.vanderbilt.edu/PsFrag .  This uses the fragmaster perl 
> script which runs LaTeX from within R to make the final graphics file 
> self-contained.

The howto is interesting and extremely useful (thank you), however there is one
line that couldn't be completed:

tab <- latexTabular(x, align='rl')  # new function in Hmisc

Which version of Hmisc has (will have) this new function?
It cannot be found in the latest version (3.4-2) from CRAN...

Best wishes,
Adrian

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


Re: [R] Performance problems to fill up a dataframe

2007-09-24 Thread Adrian Dusa

Try to assign some names to your initial variables:
dat <- data.frame(A=c(60001,60001,60050,60050,60050), B=c(27,129,618,27,1579))

And what you want is simply:
> table(dat)
   B
A   27 129 618 1579
  60001  1   1   00
  60050  1   0   11

Why do you need it as a dataframe anyway?
Hth,
Adrian

On Monday 24 September 2007, Florian Jansen wrote:
> Dear Listmembers,
>
> I'm trying to fill up a dataframe depending on an arbitrary list of
> references:
>
> Here is my code, which works:
>
> dat <- data.frame(c(60001,60001,60050,60050,60050),c(27,129,618,27,1579))
> LR <- sort(unique(dat[,1]))
> LC <- sort(unique(dat[,2]))
> m <- as.data.frame(matrix(data=NA, nrow=length(LR), ncol=length(LC),
> dimnames=list(LR,LC)))
>
> for(i in 1:nrow(dat)){
>   m[as.character(dat[i,1]), as.character(dat[i,2])] <- 1
>   }
> m[is.na(m)] <- 0
>
> Now I'm trying to prevent the loop, because it take ages for a list of
> 2 entries, but I run out of ideas.
> Should I inflate my list beforehand and how? Can I adress the dataframe
> fields more effieciently?
>
> Thanks for your help.



-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


Re: [R] programming question

2007-09-17 Thread Adrian Dusa
On Monday 17 September 2007, you wrote:
> R 2.6.0 has Reduce;
>
> myvec <- c(2, 8, 24, 26, 51, 57, 58, 78, 219)
> Reduce(function(myvec, p) setdiff(myvec, findSubsets2(p)), myvec, myvec)

Thanks Gabor, at first I jumped off my chair but... for many input variables 
it takes  to reduce the vector. My crude solution is way faster than 
Reduce()
For 9 input variables:

`findSubsets2` <- 
function(element) {
require(QCA)
base3row <- getRow(rep(3,9), element, zerobased=TRUE)
increment <- function(x, y) {
a <- x
for (i in 1:2) {
a <- as.vector(outer(y, a, "+"))
x <- c(x, a)
}
return(x)
}
indices <- which(base3row == 0)
mbase <- c(6561, 2187, 729, 243, 81, 27, 9, 3, 1)
for (i in indices) {
element <- increment(element, mbase[i])
}
return(element[-1])
}


`myreduce` <- function(myvec) {
position <- 1
while(position < length(myvec)) {
falsevector <- findSubsets2(myvec[position])
myvec <- setdiff(myvec, falsevector)
position <- position + 1
}
return(myvec
}


The timings for the tests:
set.seed(1)
myvec1 <- myvec2 <- sort(sample(3^9, 3^8)) - 1

> system.time(myvec1 <- myreduce(myvec1))
   user  system elapsed
  0.200   0.004   0.204

> system.time(myvec2 <- Reduce(function(myvec2, p) setdiff(myvec2, 
findSubsets2(p)), myvec2, myvec2))
   user  system elapsed
 12.093   0.000  12.095

With 14 input variables my function takes 24 seconds to complete, and I'd like 
to process 20 such input variables (their complexity grow exponentially)...

Thanks again,
Adrian



-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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


[R] programming question

2007-09-16 Thread Adrian Dusa

Dear list,

I have a vector of numbers, let's say:

myvec <- c(2, 8, 24, 26, 51, 57, 58, 78, 219)

My task is to reduce this vector to non-reducible numbers; small numbers can 
cross-out some of the larger ones, based on a function let's say called 
reduce()

If I apply the function to the first element 2, my vector gets shorted to:
> (myvec <- reduce(myvec[1]))
 [1]   2   24   51   57   58   78  219

The next element that can further reduce the vector is the second (24) and a 
next iteration further reduces it and so on, until nothing can be reduced.

The question is, what is the best programming technique to achieve this?

My crude solution is:

position <- 1 # start with the first position in the vector (smallest number)
while(position < length(myvec)) {
myvec <- reduce(myvec[position])
position <- position + 1
}


Is there a better programming approach?
Some vectors have lengths of millions, so this one takes a very long time.

Thanks in advance,
Adrian



PS: below is a self-contained example:
The initial vector corresponds to the following lines in a base 3 matrix:
  [,1] [,2] [,3] [,4] [,5]
   2 00002
   8 00022
  24 00220
  26 00222
  51 01220
  57 02010
  58 02011
  78 02220
 219 22010

In the first iteration, the first element 2 eliminates 8 and 26 because both 
contain number 2 in the last position (first line being shorter).
The element 24 eliminates 51 and 78, and so on.

`findSubsets2` <-
function(element) {
require(QCA)
base3row <- getRow(rep(3,5), element, zerobased=TRUE)
increment <- function(x, y) {
a <- x
for (i in 1:2) {
a <- as.vector(outer(y, a, "+"))
x <- c(x, a)
}
return(x)
}
indices <- which(base3row == 0)
mbase <- c(81, 27, 9, 3, 1)
for (i in indices) {
element <- increment(element, mbase[i])
}
return(element[-1])
}

position <- 1
while(position < length(myvec)) {
falsevector <- findSubsets2(myvec[position])
myvec <- setdiff(myvec, falsevector)
position <- position + 1
}




-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

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