[R] How to access https page

2015-03-09 Thread Hui Du
Hi All, I am trying to parse some information from website, say, a linkedin page. The linkedin url was url = http://www.linkedin.com/in/huidu; I had no problem to use readLines and XML package to collect the information I need. However, that url became https://www.linkedin.com/in/huidu; now.

[R] test if a url exists

2014-06-28 Thread Hui Du
Hi all, I need to test if a url exists. I used url.exists() in RCurl package library(RCurl) however the test result is kind of weird. For example, url.exists(http://www.amazon.com;) [1] FALSE although www.amazon.comhttp://www.amazon.com is a valid url. Does anybody know how to use that

[R] object.size vs. workspace size

2014-03-06 Thread Hui Du
Hi All, I have 2 objects, A and B, where object.size(A) = 5M and object.size(B) = 80M. However, after I save those two objects as workspaces, say, save(A, file = A.Rdata) and save(B, file = B.Rdata) On disk, the size of 'A.Rdata' is 0.22 M but the size of 'B.Rdata' is 560M. Could someone

[R] test the return from grep or agrep

2014-03-01 Thread Hui Du
Hi All, My sample code looks like options(stringsAsFactors = FALSE); clean = function(x) { loc = agrep(ABC, x$name); x[loc,]$new_name - NEW; x; } name = c(12, dad, dfd); y = data.frame(name = as.character(name), idx = 1:3); y$new_name = y$name; z - clean(y) The snippet does not

[R] R build a package

2014-01-17 Thread Hui Du
Hi All, While building a package by 'R CMD INSTALL --build my-own-pack-name', I always got an error like Error in normalizePathpath.expandpath, winslash, mustWork: path[1] = ./DESCRIPTION: Access is denied. I checked the permission of my DESCRIPTION file and it looks right. Does anybody

[R] rJava works on R-32bit but fails in R 64bit

2014-01-14 Thread Hui Du
Hi All, I have R 64bit and R-32 bit installed in my windows 7. For 64 bit, the version info is R.Version() $platform [1] x86_64-w64-mingw32 $arch [1] x86_64 $os [1] mingw32 $system [1] x86_64, mingw32 $status [1] $major [1] 3 $minor [1] 0.2 $year [1] 2013 $month [1] 09 $day [1] 25

[R] plot multiple graphs in one graph and in multiple windows

2013-09-26 Thread Hui Du
Hi All, I have a question about plotting graphs. Supposedly, I want to plot 12 graphs. Putting 12 graphs to one window seems too crowded. Ideally, I want to put 4 pictures in one window and plot them in three separate window. For exmaple, my psuedo code is like par(mfrow = c(2, 2)) for( I

[R] set breakpoint in debug

2013-09-16 Thread Hui Du
Hi All, I need some help regarding how to set up a breakpoint in debug. For example, I have a very simple/naïve function (a useless function just for demo) f = function() { x = 10; len = 100; a = 1; for(i in 1:len) { a = a * i; } y = x + a; y; } If I need to

[R] 'snow' package -- parallel process

2013-09-04 Thread Hui Du
Hi R-community: I heard 'snow' package is a good tool to parallelize processes and speed them up. I tried to use it but was not successful. Could someboy point where I was wrong? Thanks. I want to read a HUGE file to R and hope 'snow' helps me to speed it up. Here are codes: library(snow)

[R] read data from a URL with login required

2013-07-20 Thread Hui Du
Hi All, How to read a URL requiring log in info in R? For example, I want to download some info from Linkedin pages, my username is abc, password is 123. How can I download my desired URL page in R? Many thanks. HXD [[alternative HTML version deleted]]

[R] error in installation

2013-05-28 Thread Hui Du
Hi All, We have tried to install R in AIX. But it seems the installation is not complete because when we run R, we always get an error message like XXXR Error in objects(i, all.names = TRUE) : failed to open ICU collator And if we want to install a new package, we get install.packages

[R] replace data by a rule

2013-05-06 Thread Hui Du
Hi All, I have data set like x = data.frame(id = 1:8, f1 = LETTERS[1:8]) I want to replace id 5, 6, 7, 8 by 1, 2, 3, 4 respectively. e.g the map is ID-1 ID-2 5 1 6 2 7 3 8 4 I have lots of data and rules. How to do it in a few lines rather than do them one by one like: x[x$id ==

[R] Self-developed package -- installation

2013-05-02 Thread Hui Du
Hi All, I have a question about package installation in R. We have developed a package, say 'ABC'. We have installed it in two machines, A and B by running 'Install Package(s) from local zip file'. Everything was fine. Right now, suppose that package got damaged in machine A and our zipped

[R] how to re-shape a matrix

2013-04-03 Thread Hui Du
Hi All, I have a matrix like m - matrix( letters[1:10], ncol=5) How to conver it to 10 * 3 matrix, which the first col is row index of m, second col is colum index of m and third column is the value of matrix, say 11 1a 21 2 c 1 3 e etc... Thanks.

[R] how to read a website with Chinese Character

2013-01-23 Thread Hui Du
Hi all, I am planning to parse some information on a website which includes lots of Chinese characters. Does someone know how to read/display Chinese in R? Thanks. url = http://www.teec.org.cn/html/renwujieshao/; x = readLines(url) I tried encoding = 'UTF-8' already but it didn't help. My R

Re: [R] how to read a website with Chinese Character

2013-01-23 Thread Hui Du
Thanks a lot. y - iconv(x, gb2312, utf-8) does not work but y - iconv(x, gb2312, UTF8) works on my machine. Thank you for pointing to the right direction. -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: Wednesday, January 23, 2013 6:16 PM To: Hui Du

[R] R and SPSS

2012-11-06 Thread Hui Du
Hi group: I have a data set, which has severe colinearity problem. While running linear regression in R and SPSS, I got different models. I am wondering if somebody knows how to make the two software output the same results. (I guess the way R and SPSS handling singularity is different, which

[R] backward stepwise model selection

2012-10-26 Thread Hui Du
Hi All, I know in R there is function named 'step', which does the stepwise regression and choose the model by AIC. However, if I want to choose a model per this logic: 1. Run a full model (linear regression, f = lm(y ~., data = ZZZ), for example) 2. Pick up the variable with

[R] Variance Inflation factor

2012-07-11 Thread Hui Du
Hi All, I need to calculate VIF (variance inflation factor) for my linear regression model. I found there was a function named vif in 'HH' package. I have two questions: 1) I was able to install that package in my R under windows. But while trying to install that package in UNIX, I

Re: [R] Variance Inflation factor

2012-07-11 Thread Hui Du
Thanks. But in UNIX side, I got the same error In getDependencies(pkgs, dependencies, available, lib) : package ‘car’ is not available HXD From: Jorge I Velez [mailto:jorgeivanve...@gmail.com] Sent: Wednesday, July 11, 2012 3:19 PM To: Hui Du Cc: R-help Subject: Re: [R] Variance

Re: [R] Variance Inflation factor

2012-07-11 Thread Hui Du
To: Hui Du Cc: R-help Subject: Re: [R] Variance Inflation factor Could you please include your sessionInfo() ? Thank you, Jorge.- On Wed, Jul 11, 2012 at 6:27 PM, Hui Du hui...@dataventures.commailto:hui...@dataventures.com wrote: Thanks. But in UNIX side, I got the same error

Re: [R] Variance Inflation factor

2012-07-11 Thread Hui Du
Message- From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com] Sent: Wednesday, July 11, 2012 4:04 PM To: Hui Du Cc: Jorge I Velez; R-help Subject: Re: [R] Variance Inflation factor You're rather out of date with your version of R -- if you want to use the CRAN binaries provided

[R] install.packages

2012-07-09 Thread Hui Du
Hi All, I have two questions regarding install.packages(). Q1: may I run it in non-interactive mode, which means just install the packages I want rather than letting me to choose which mirror etc? Q2: I ran a R code in batch mode, for example, R CMD BATCH a.r In a.r, I have some statements

Re: [R] install.packages

2012-07-09 Thread Hui Du
Thanks Sarah. I realized it as well and tried to run install.packages(plyr, lib = .Library) as root. It works now. Thanks again. HXD -Original Message- From: Sarah Goslee [mailto:sarah.gos...@gmail.com] Sent: Monday, July 09, 2012 12:06 PM To: Hui Du Cc: r-help@r-project.org Subject

[R] pad leading zeros in front of strings

2012-05-22 Thread Hui Du
Dear All, This question sounds very simple but I don't know where I am wrong. I just want to pad leading zeros in some string, for example, 123 becomes 00123. What is wrong if I do following? sprintf(%05s, 123) [1] 123 It didn't return 00123, instead it padded with 'blank'. Thank you

Re: [R] pad leading zeros in front of strings

2012-05-22 Thread Hui Du
...@gmail.com] Sent: Tuesday, May 22, 2012 12:00 PM To: Sarah Goslee Cc: Hui Du; r-help@r-project.org Subject: Re: [R] pad leading zeros in front of strings I get 00123 and 00abc respectively. Agreed it's perhaps odd, but c'est la OS. M On Tue, May 22, 2012 at 2:57 PM, Sarah Goslee sarah.gos

[R] apply one list to another one

2012-05-03 Thread Hui Du
Hi All, Suppose I have the following codes: x = data.frame(A = rnorm(20), B = rnorm(20), C = rnorm(20)) a = list() a[[1.1]] = x a[[1.2]] = x b = list() b[[1.1]] = c(A, B) b[[1.2]] = c(B, C) Now I want to apply b to a like this, for each element of 'a', only select the corresponding columns

[R] re-install a package

2012-04-10 Thread Hui Du
Hi All, I have a self-cooked package and save it to a zip file after running make, say named xxx.zip. After installing it to R by running Install packages from local zip files under Packages menu in R (Windows), I realized I needed to change some source codes and re-make it. My

[R] rodbc -- save result to a table

2011-12-12 Thread Hui Du
Hi All, I am pretty new for RODBC. I want to save my table to a DB, so I used something like sqlSave(db, a, 'Forecast_Result', rownames = FALSE); But I got an error Error in sqlSave(db, a, Forecast_Result, rownames = FALSE) : table 'Forecast_Result' already exists Yes, that

[R] locate the needed columns

2011-08-30 Thread Hui Du
Hi All, I have a data frame, whose colnames like A.x, B.x, C.x, A.y, B.y, C.y. There could be many columns like this pattern. I want to compare data in columns A.x with A.y, B.x with B.y and C.x with C.y etc. Suppose my data frame is d, names(d) = c(A.x, B.x, C.x, A.y, B.y,

[R] debug R code

2011-06-03 Thread Hui Du
Hi List, I have a question regarding debug R code. I know I can use debug(fuction_name) and when code runs to that point, it will go to debugger. My question is inside debugger, how to stop a code at a specified line. For example, in C (gdb or dbx debugger) I can run stop at 123

[R] line type lty

2011-04-21 Thread Hui Du
Hi All, Does somebody know how to know the detail of the line types? For example, lty = 1, means what kind of line?, lty = 2, means what kind of line? Thanks. HXD [[alternative HTML version deleted]] __

[R] output usage info to stdout

2011-04-20 Thread Hui Du
Hi all, I want to run a R code in the batch mode under UNIX system. Inside that code, I have a usage() function to give the hints regarding parameters. For example usage = function() { msg = R CMD BATCH --save \--args path=\\\input_path\\\ file=\\\input_file\\\

[R] apply mean to a three-dimension data

2011-03-24 Thread Hui Du
Hi All, Suppose I have data like b[[1]] = matrix(1:4, 2, 2) b[[2]] = matrix(10:13, 2, 2) b[[3]] = matrix(20:23, 2, 2) [[1]] [,1] [,2] [1,]13 [2,]24 [[2]] [,1] [,2] [1,] 10 12 [2,] 11 13 [[3]] [,1] [,2] [1,] 20 22 [2,] 21 23

[R] apply mean to a three-dimension data

2011-03-24 Thread Hui Du
Hi All, Suppose I have data like [[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

Re: [R] aggregate by part of a field

2011-03-10 Thread Hui Du
, like a, b c, a bdfd c and def e h in my example. It is not necessary just three letters, so substr may not work. Sorry for the confusion. HXD From: Dennis Murphy [mailto:djmu...@gmail.com] Sent: Wednesday, March 09, 2011 11:30 PM To: Hui Du Cc: r-help@r-project.org Subject: Re: [R] aggregate

[R] aggregate by part of a field

2011-03-09 Thread Hui Du
Hi All, I have a data frame like a = data.frame(date = c(20081201, 20081202, 20081201), product = c(a b c d e, a b c g h t, d e h a c e h g), sales = c(1, 2, 3)) Now I want to aggregate the sales by part of the a$product. 'Product' is the product name, a

[R] R in different OS

2011-02-25 Thread Hui Du
Hi All, I have two Rs, one has been installed in Windows system and another one has been installed under UNIX system. Is there any environmental variable or function to tell me which R I am using? The reason that I need to know it is under different system, the data path could

Re: [R] R in different OS

2011-02-25 Thread Hui Du
Great. Thanks. Best Regards, Hui Du Data Ventures Inc -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Friday, February 25, 2011 12:59 PM To: Hui Du Cc: r-help@r-project.org Subject: Re: [R] R in different OS On Feb 25, 2011, at 1:23 PM, Hui Du wrote

[R] speed up the code

2011-02-16 Thread Hui Du
Hi All, The following is a snippet of my code. It works fine but it is very slow. Is it possible to speed it up by using different data structure or better solution? For 4 runs, it takes 8 minutes now. Thanks a lot fun_activation = function(s_k, s_hat, x_k, s_hat_len) { common =

[R] Repeaded sampling

2011-02-10 Thread Hui Du
Hi all, I have a dataset. Each time I want to sample N(i) elements from it and I want to repeated sampling M times. N(i) is varied from time to time. For example, dataset = 1:50; a = list(); M = 1000; I want to