ormp Unix Shell Code Practice

EZ Study

Actuarial Biology Chemistry Economics Calculators Confucius Engineer
Physics
C.S.

Small but Powerful R Tips --I

R Error 1: Error in plot.new() : figure margins too large

Every time you are creating plots you might get this error - "Error in plot.new() : figure margins too large". To avoid such errors you can first check par("mar") output. You should be getting:

[1] 5.1 4.1 4.1 2.1
To change that write:
par(mar=c(1,1,1,1))
This should rectify the error.

2. want to break the data into 2 parts: even number of rows and odd number of rows, within each group by:
data1f = transform(data1f,a=1)
data1f$num<-ave(data1f$a,list(data1f$Ln1,data1f$Fn1),FUN=cumsum)
data1f = transform(data1f,mod=num%%2,block=(num+99)%/%100)
data1f = transform(data1f,block=sprintf("%02d",block))  ## Z2. function

paste0() function to combine without blanks, also the tip to proper() function:
data1c=transform(data1c,Ln=paste0(toupper(substr(Lna, 1, 1)), 
tolower(substring(Lna, 2))))
paste (..., sep = " ", collapse = NULL)
paste0(..., collapse = NULL)
paste0(..., collapse) is equivalent to paste(..., sep = "", collapse),
slightly more efficiently.

i=1;
url=paste("http://www-personal.umich.edu/~alandear/tree/Z",i,".HTM")
url <- gsub(" ","",url)
parsedHTML <- htmlParse(url)
parsedHTML
hrefs <- xpathSApply(parsedHTML, "//a", xmlGetAttr, 'href')
## to geth the value under behind the url.
hrefs
names <- xpathSApply(parsedHTML, "//a", xmlValue,'href') 
## to geth the acutally value in the url.
names
a1=cbind(hrefs,names)
dim(a1)
You will probably get the following error if you have used cbind and sqldf in your code:

Error in sqliteSendQuery(conn, statement, bind.data) : 
RAW() can only be applied to a 'raw', not a 'character'
The reason is due to the class the columns is list. You need to switch to other classes like: factor/numerio/character via:

a1e$name <- as.character(a1e$name)
a1e$hrefs <- as.character(a1e$hrefs)
sapply(a1e,class)
Related links:
Continue to Formatting SQL query, Tips to use Group Statement   SAS Interview

Back to R code practice in Unix Shell Whorkshop-I   Analytics Home