Re: [R] frequency table-visualization for complex categorical variables

2013-02-26 Thread Rui Barradas
Hello, I'm not sure I understand, do you want to treat BCC, CBC and CCB as the same? If so try w2 <- apply( y , 1 , function(x) paste0(sort(x) , collapse = "" )) table(w2) Hope this helps, Rui Barradas Em 26-02-2013 13:58, Niklas Fischer escreveu: Hi again, Thanks

Re: [R] cut a vector in equal parts

2013-02-26 Thread Rui Barradas
Hello, Try the following. x <- rnorm(500)^2 split(x, cut(x, quantile(x, probs = seq(0, 1, by = 0.2 Hope this helps, Rui Barradas Em 26-02-2013 17:39, Martin Batholdy escreveu: Hi, I would like to cut a vector of values in parts. Each part should have an equal number of elements.

Re: [R] ARMA and AR in R

2013-02-28 Thread Rui Barradas
Hello, This is a statistics question, not an R one. If you want to fit an ARMA model, your time series can have any values, zero, negative or positive. Please revise your knowledge of time series. Hope this helps, Rui Barradas Em 28-02-2013 10:40, Nnina escreveu: Hello, I would like to

Re: [R] Hidden information in an object

2013-03-01 Thread Rui Barradas
l be selected. Read An Introduction to R, file R-intro.pdf in the doc directory of your installation of R, section 2.7 - Index Vectors. Hope this helps, Rui Barradas If I write the code like library(MASS)cats$ratio <- cats$Hwt/cats$Bwtmale <- cats$ratio[cats$Sex == "M"]... it als

Re: [R] solving x in a polynomial function

2013-03-01 Thread Rui Barradas
realroots(po.lm, 5.5) predict(po.lm, newdata = data.frame(b = r)) # confirm Hope this helps, Rui Barradas Em 01-03-2013 18:47, Mike Rennie escreveu: Hi there, Does anyone know how I solve for x from a given y in a polynomial function? Here's some example code: ##example file a<-1:10 b<-

Re: [R] solving x in a polynomial function

2013-03-01 Thread Rui Barradas
Thanks. Rui Barradas Em 01-03-2013 20:35, arun escreveu: Hi Rui, Looks like a bug: ###if(names(model)[1] = "(Intercept)") Should this be: if(names(model)[1] == "(Intercept)") A.K. - Original Message - From: Rui Barradas To: Mike Rennie Cc: r-help Mailin

Re: [R] solving x in a polynomial function

2013-03-01 Thread Rui Barradas
coef(model))[1] == "(Intercept)") r <- polyroot(c(coef(model)[1] - b, coef(model)[-1])) else r <- polyroot(c(-b, coef(model))) Re(r[is.zero(Im(r))]) } r <- realroots(po.lm, 3) predict(po.lm, newdata = data.frame(b = r)) # confirm 1 2

Re: [R] replace zeros for NA in a column based on values of another column

2013-03-02 Thread Rui Barradas
Hello, Try # for columns a.b it's 1:2, not 1:3 data[data[,4] == 0, 1:3] <- NA # columns a, b and c Hope this helps, Rui Barradas Em 02-03-2013 10:26, Camilo Mora escreveu: Hi everyone, Imagine that I have a data frame with four columns: data<- a b c d 0

Re: [R] replace zeros for NA in a column based on values of another column

2013-03-02 Thread Rui Barradas
.matrix(dat) str(dat) dat[, 1:2] <- sapply(1:2, function(i) ifelse(dat[, i] == 0 & dat[, 4] == 0, NA, dat[, i])) Hope this helps, Rui Barradas Em 02-03-2013 16:11, arun escreveu: HI, Not sure I understand it correctly, data1<-read.table(text=" a b c d 0

Re: [R] Errors-In-Variables in R

2013-03-02 Thread Rui Barradas
There's a no homework policy in R-help. Rui Barradas Em 02-03-2013 18:28, Cedric Sodhi escreveu: In reference to [1], how would you solve the following regression problem: Given observations (X_i,Y_i) with known respective error distributions (e_X_i,e_Y_i) (say, 0-mean Gaussian with know

Re: [R] Errors-In-Variables in R

2013-03-02 Thread Rui Barradas
Hello, Like you say, apparently R doesn't have models for error in variables. But R packages might have. library(sos) findFn('errors-in-variables') Some look promising. Hope you find something. Rui Barradas Em 02-03-2013 21:55, Cedric Sodhi escreveu: Perhaps it would have be

Re: [R] Kolmogorov-Smirnov: calculate p value given as input the test statistic

2013-03-03 Thread Rui Barradas
st provide at least on sample and a CDF. Something like x <- rnorm(100) f <- ecdf(rnorm(100)) ks.test(x, f) Hope this helps, Rui Barradas Em 03-03-2013 09:58, Rani Elkon escreveu: Dear all, I calculate the test statistic for the KS test outside R, and wish to use R only to calculate

Re: [R] how_to_create_a_package?

2013-03-05 Thread Rui Barradas
Hello, Another document that could help is Friedrich Leisch, Creating R Packages: A Tutorial, that can be found at http://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf Hope this helps, Rui Barradas Em 05-03-2013 11:15, Jim Lemon escreveu: On 03/05/2013 02:42 PM, Jyoti Sharma

Re: [R] Plotting time data for various countries in same graph

2013-03-06 Thread Rui Barradas
China 9 2010Q4 China 14 ", header = TRUE) dat$Time <- as.numeric(sub("Q", "\\.", dat$Time)) p <- ggplot(dat,aes(x=Time,y=Values,colour=Country)) p + geom_line() Hope this helps, Rui Barradas Em 06-03-2013 08:06,

Re: [R] combining column having same values

2013-03-06 Thread Rui Barradas
Hello, Try x <- scan(text = " 1 1 3 2 3 1 1 2 3 3 2") sapply(unique(x), function(.x) which(x == .x)) Hope this helps, Rui Barradas Em 06-03-2013 11:26, eliza botto escreveu: Dear useRs, I have a matrix in the following form

Re: [R] Coversion from yearly to weekly data

2013-03-08 Thread Rui Barradas
Hello, Something like this? sp <- split(test, test$Data) res <- do.call(rbind, lapply(sp, function(x){ Week <- (seq_len(nrow(x)) %/% 7) + 1 aggregate(Value ~ Data + Week, data = x, FUN = mean)})) rownames(res) <- seq_len(nrow(res)) res Hope this helps, Rui Barrad

Re: [R] Word Frequency for each row

2013-03-08 Thread Rui Barradas
(where, length) # count them Hope this helps, Rui Barradas Em 08-03-2013 16:04, Sudip Chatterjee escreveu: Hi All, I am wondering if there is any examples where you can count your interested "word" in each row. For an example if you have data with *'ID*' and '*w

Re: [R] Word Frequency for each row

2013-03-08 Thread Rui Barradas
Hello, I had thought of something like that, but I'm not sure if the match must be exact. If not, grep seems better. More complicated and slower but more flexible. Rui Barradas Em 08-03-2013 21:32, arun escreveu: Hi, You can also try: res2<-rowSums(x==word) res1<-sapply(w

Re: [R] Calculation with date

2013-03-09 Thread Rui Barradas
lt;- function(x, y){ s <- as.integer(format(x, "%m")) + y yx <- as.integer(format(x, "%Y")) + (s %/% 12) as.Date(paste(yx, s %% 12, "01", sep = "-")) } pm <- plusmonths(Date, Vec) identical(New_Vec, pm) # TRUE Hope this he

Re: [R] Finding where a string drops below a certain value

2013-03-09 Thread Rui Barradas
Hello, The following functions will return an index to the required values, not the values themselves. firstzero <- function(x) which(x == 0)[1] lastone <- function(x){ z <- firstzero(x) if(z == 1) NULL else z - 1 } Hope this helps, Rui Barradas Em 09-03-2

Re: [R] Word Frequency for each row

2013-03-09 Thread Rui Barradas
anges so eat oranges ", sep = ",", header = TRUE, stringsAsFactors = FALSE) dat word <- "oranges" where <- sapply(dat$Data, function(.x) gregexpr(tolower(word), tolower(.x))) result <- sapply(where, length) # count them names(result) <- dat$ID result Hope t

Re: [R] Changing default order of plots in par

2013-03-09 Thread Rui Barradas
Hello, Instead of mfrow use mfcol and the order becomes col by col. Hope this helps, Rui Barradas Em 09-03-2013 20:55, Brian Smith escreveu: Hi, I wanted to change the order of how the plots appear in a multiplot scenario. For example, in the code below: # pdf('test.pdf

Re: [R] kruskal test

2013-03-10 Thread Rui Barradas
Hello, That error occurs if you have Inf values in vekkat. Try to see them with finite <- is.finite(vekkat) sum(!finite) If this is not zero, you can fix your test with kruskal.test(wis1[finite] ~ vekkat[finite]) Hope this helps, Rui Barradas Em 10-03-2013 10:37, Adriana Škrinár

Re: [R] plot pch

2013-03-11 Thread Rui Barradas
eally important here) plot(1, type = "n", xlim=c(0, 17), ylim=c(0, 17)) for(x in 1:16) for(y in 1:16) points(x, y, pch = (x - 1)*16 + y) They go first column with x = 1, from y = 1 to 16, etc. Hope this helps, Rui Barradas Em 11-03-2013 17:43, eliza botto escreveu: Dear xpeRts

Re: [R] split data into columns from dataframe

2013-03-12 Thread Rui Barradas
(PARTIAL) 94.6 at interval beginning 19800329 063532 ") # Simple data_30min[, c(2, 4, 8)] # More elaborate, but equivalent subset(data_30min, select = c("V2", "V4", "V8")) Hope this helps, Rui Barradas Em 12-03-2013 09:03, Roslina Zakaria escreveu: Dear r-users

Re: [R] extract values

2013-03-12 Thread Rui Barradas
try y <- as.numeric(names(x)) x[y > 1820] Hope this helps, Rui Barradas Em 12-03-2013 17:50, catalin roibu escreveu: Hello all! I have a problem to extract values greater that for example 1820. I try this code: x[x[,1]>1820,]->x1 Please help me! Thank you! The data structure is: stru

Re: [R] big edge list to adjacency matrix

2013-03-12 Thread Rui Barradas
Hello, The following is a bit convoluted but will do it. dat <- read.table(text = " a1 b1 1 a2 b2 2 a3 b3 3 a1 b1 4 a3 b1 5 ") xtabs(V3 ~ V1 + V2, data = aggregate(V3 ~ V1 + V2, data = dat, FUN = max)) Hope this helps, Rui Barradas Em 12-03-2013 21:45, avinash sahu escreveu:

Re: [R] Bootstrap encounter histories data

2013-03-14 Thread Rui Barradas
f <- function(y){ idx <- sample(nrow(y), nrow(y), replace = TRUE) y[idx, ] } res <- do.call(rbind, lapply(split(x, x[, 2]), f)) rownames(res) <- seq_len(nrow(res)) res } fun(dat) Hope this helps, Rui Barradas Em 14-

Re: [R] Bootstrap encounter histories data

2013-03-14 Thread Rui Barradas
o.call(rbind, lapply(sp, f)) rownames(res) <- seq_len(nrow(res)) res } fun(mat) Hope this helps, Rui Barradas Em 14-03-2013 11:34, Rui Barradas escreveu: Hello, It doesn't seem very complicated. First of all, for the function fun below to work, you need the data not

Re: [R] Question on assignment

2013-03-16 Thread Rui Barradas
available to the parent.env of x1(), if x1() succeeds. Hope this helps, Rui Barradas Em 16-03-2013 13:27, Christofer Bogaso escreveu: Hello again, I was trying to understand how I can assign variables in some other Environments which is different from that variable's original Envi

Re: [R] multiple frequencies per second again

2013-03-16 Thread Rui Barradas
Hello, The answer to your question is no, you don't have to do anything special, except, of course, say how many steps ahead you want to predict. To see this, run the second example in ?predict.Arima. It predicts 6 steps ahead, accounting for the frequency. Hope this helps, Rui Barrada

Re: [R] help with simple function

2013-03-17 Thread Rui Barradas
(Y2) - cov(Y1, Y2)^2)) x1 <- rnorm(10) x2 <- rnorm(10) fun(x1, x2) Hope this helps, Rui Barradas Em 17-03-2013 15:47, Miguel Eduardo Delgado Burbano escreveu: hello all I am writing a quite simple script to study dental wear patterns in humans and I wrote this function sqrt(var(Y1)+

Re: [R] How make a boxplot with Y axis in percentage

2013-03-17 Thread Rui Barradas
e a data example is to use dput(): dput(dat) # paste the output of this in a post. That's the structure() above. Hope this helps, Rui Barradas Em 17-03-2013 12:50, Larissa Schneider Guilhon escreveu: I have to make a boxplot with Years 2011 and 2012 on the x axis, and percentage of full

Re: [R] Counting confidence intervals

2013-03-18 Thread Rui Barradas
Hello, There _is_ a function ?within. Maybe your function can be named 'between' Rui Barradas Em 18-03-2013 16:16, S Ellison escreveu: I want to cont how many times a number say 12 lies in the interval. Can anyone assist? Has anyone else ever wished there was a moderately gener

Re: [R] Superscript followed by number then superscript in text

2013-03-18 Thread Rui Barradas
Hello, Something like this? plot(1, type = "n") text(1,1, expression(capacity ~ 10^3 ~ m^3)) Hope this helps, Rui Barradas Em 18-03-2013 20:29, Benjamin Gillespie escreveu: Hi all, I'm having problems finding the correct format for a command. I would like to write some

Re: [R] Cumulative Frequency Graph

2013-03-19 Thread Rui Barradas
lative eruptions", # y−axis label xaxt = "n") lines(breaks, cumfreq0) axis(1, at = duration) Hope this helps, Rui Barradas Em 19-03-2013 12:34, Shane Carey escreveu: Hi, I am trying to create a Cumulative Frequency graph and I am using the following example: http://www.r

Re: [R] How to get the t-stat for arima()?

2013-03-19 Thread Rui Barradas
Hello, Using a dataset in package datasets, n <- length(lh) fit <- arima(lh, order = c(1,0,0)) se <- sqrt(diag(vcov(fit))) sqrt(n - 1)*coef(fit)/se # T stats Hope this helps, Rui Barradas Em 19-03-2013 20:22, Yuan, Rebecca escreveu: Hello all, fit = arima() and Summary(fit)

Re: [R] How to get the t-stat for arima()?

2013-03-19 Thread Rui Barradas
Hello, Sorry for the error, the sqrt(n - 1) is wrong. Delete it: t.stat <- coef(fit)/se Rui Barradas Em 19-03-2013 21:11, Rui Barradas escreveu: Hello, Using a dataset in package datasets, n <- length(lh) fit <- arima(lh, order = c(1,0,0)) se <- sqrt(diag(vcov(fit))) sqrt

Re: [R] highlight overlapping region of two densities

2013-03-20 Thread Rui Barradas
Hello, Try the following. d0 <- density(myd) d1 <- density(myd1) idx0 <- d0$x >= 1 & d0$x <= 4 idx1 <- d1$x >= 1 & d1$x <= 4 yy <- apply(cbind(d0$y[idx0], d1$y[idx1]), 1, min) xx <- d0$x[idx0] xx <- c(xx[1], xx, xx[1]) yy <- c(0, yy, 0) polygon(x

Re: [R] How to look at the source code for predict()

2013-03-20 Thread Rui Barradas
Hello, In the case of predict.Arima, you can type at an R prompt the following. stats:::predict.Arima Hope this helps, Rui Barradas Em 20-03-2013 18:43, Yuan, Rebecca escreveu: Hello all, I thought I found it, it is in the arima.R if I use arima to fit the model. But how could we see the

Re: [R] boot with different sample sizes

2013-03-20 Thread Rui Barradas
test1<-function(x, d, y){ return(sum(x[d]) - sum(y)) } b <- boot(red, test1, R=10, y = blue) b sum(red) - sum(blue) Hope this helps, Rui Barradas Em 20-03-2013 22:49, paolo brunori escreveu: Dear all, a question about the package boot: is it possible to bootstrap a function of ar

Re: [R] problem subsetting data.frame in R version 2.15.2 for Windows

2013-03-20 Thread Rui Barradas
s very clear. What you have is an element of the data.frame named 'a', that can be accessed like data$a or data[["a"]]. Use the first way of subsetting the data.frame. Also, 'data' is a bad name for an object, it already is a function name. Hope this helps, Rui Bar

Re: [R] How could I specify "no interception term" in arima?

2013-03-21 Thread Rui Barradas
Hello, In fact, it's written there, in ?arima: "Further, if include.mean is true (the default for an ARMA model), this formula applies to X - m rather than X." So, use include.mean = FALSE Hope this helps, Rui Barradas Em 21-03-2013 13:56, Yuan, Rebecca escreveu: Hello,

Re: [R] Could I get the following stats from arima()?

2013-03-21 Thread Rui Barradas
to one of your previous posts by Prof.Brian Ripley. If it's not available in R, there must be a good reason why not. Rui Barradas Thanks, Rebecca -- This message, and any attachments, is for the intended r...{{d

Re: [R] order statistic of multivariate normal

2013-03-21 Thread Rui Barradas
Hello, Em 21-03-2013 21:42, Albyn Jones escreveu: R^n for n > 1 is not an ordered set. Theorem. All sets are well ordered. (This theorem is equivalent to the Axiom of Choice.) Rui Barradas albyn On Thu, Mar 21, 2013 at 02:32:44PM -0700, David Winsemius wrote: On Mar 21, 2013, at 1

Re: [R] A question on function return

2013-03-22 Thread Rui Barradas
se NA, if(y > 0) Vec2 else NA) } fn2(-3, -3) fn2(3, -3) Hope this helps, Rui Barradas Em 22-03-2013 18:43, Christofer Bogaso escreveu: Hello again, Let say I have following user defined function: fn <- function(x, y) { Vec1 <- letters[1:6] Vec2 <-

Re: [R] Double condition

2013-03-22 Thread Rui Barradas
Hello, Try the following. idx <- which(subz$fix == "noon") if(idx[length(idx)] == nrow(subz)) idx <- idx[-length(idx)] subz$day[idx + 1] <- subz$day[idx] Hope this helps, Rui Barradas Em 22-03-2013 18:18, zuzana zajkova escreveu: Hi, I would appreciate if somebody coul

Re: [R] ggplot2 will not draw a rectangle. Error: ggplot2 doesn't know how to deal with data of class XXX"

2013-03-22 Thread Rui Barradas
x27;, alpha=0.2) Hope this helps, Rui Barradas Em 22-03-2013 21:01, John Kane escreveu: Ah , thanks Sarah So that's why the error message changed! I was getting different one earlier. I had defined rect earlier and apparently, when stripping down the code I negelected to include it in t

Re: [R] Saving a Random Forest Model

2013-03-23 Thread Rui Barradas
Hello, ?save can save any R object. To load it back into R, use ?load. Hope this helps, Rui Barradas Em 23-03-2013 10:35, Lorenzo Isella escreveu: Dear All, Please consider the snippet at the end of the email The output of the randomForest model is rf1 (i.e. the trained model). Now, is there

Re: [R] Error with custom function in apply: ”Error in FUN(newX[, i], ...) : unused argument(s) (newX[, i])”

2013-03-23 Thread Rui Barradas
6], 2) : object 'Result' not found So there's some debugging to be done. Anyway, the revised loop should be much faster. Hope this helps, Rui Barradas Em 23-03-2013 11:08, Camilo Mora escreveu: Hi everyone, I wonder if I can get your help using a custom function in apply. Imagi

Re: [R] help on writing a function

2013-03-23 Thread Rui Barradas
Hello, Try this one liner. g2 <- 50 * prod(exp(-x*a)) identical(g, g2) # TRUE Hope this helps, Rui Barradas Em 23-03-2013 11:27, Andras Farkas escreveu: Dear All If you could please help me with a solution on the following: we have: a <-matrix(c(1,2,3,4,5)) x <

Re: [R] Converting a character vector to numeric

2013-03-23 Thread Rui Barradas
Hello, Try the following. It issues a warning because of the second as.numeric. (It still has the parenthesis.) ifelse(grepl("\\(", Vec), -as.numeric(sub("\\((.*)\\)", "\\1", Vec)), as.numeric(Vec)) Hope this helps, Rui Barradas Em 23-03-2013 19:51, Chri

Re: [R] Double condition

2013-03-25 Thread Rui Barradas
i2 <- which(as.character(x$fix) == "midnight") x$day[i2] <- x$day[i1] x}) names(tmp) <- NULL result <- do.call(rbind, tmp) Hope this helps, Rui Barradas Em 25-03-2013 14:15, zuzana zajkova escreveu: Hi Rui, thank you for your code, but unfortunately it doe

Re: [R] count NAs with aggregate

2013-03-25 Thread Rui Barradas
A var3[sample(100, 10)] <- NA mydataset <- data.frame(var1, var2, var3, subject, time) count_nas <- function(arg1) { return(sum(is.na(arg1))) } aggregate(mydataset[, 1:3], list(mydataset$subject, mydataset$time), FUN = count_nas) Hope this helps, Rui Barradas Em 25-03-2013 15:

Re: [R] Obtaining the internal integer codes of a factor XXXX

2013-03-25 Thread Rui Barradas
Hello, Though I have the same doubt as Bert, the following seems to make more sense. seq_along(levels(fdata)) Hope this helps, Rui Barradas Em 25-03-2013 15:37, Dan Abner escreveu: Hi everyone, I understand the process of obtaining the internal integer codes for the raw values of a

Re: [R] barplot colors

2013-03-26 Thread Rui Barradas
nging the code for barplot(). Hope this helps, Rui Barradas Em 26-03-2013 18:09, Francois de Ryckel escreveu: Dear all, I have a 2 by 2 matrix and I would like to do a barplot with it. (so 2 bars with each having 2 stacks.). I would like to have one colors per stack, so 4 different c

Re: [R] barplot colors

2013-03-26 Thread Rui Barradas
Hello, I forgot to add that if you use argument beside = TRUE, you can have as many colors as there are bars, but this is not the kind of graph you want. (This behavior makes a lot of sense if you look at the underlying code for barplot.) Rui Barradas Em 26-03-2013 19:39, Rui Barradas

Re: [R] when to use which apply function?

2013-03-26 Thread Rui Barradas
Hello, The correct syntax would be sapply(1:10, function(i) newfun(x=mat[i, 1], y=mat[i, 2], a=a, b=b)) Hope this helps, Rui Barradas Em 26-03-2013 21:51, C W escreveu: Dear list, I am a little confused as to when to use apply, sapply, tapply, vapply, replicate. I've encountered

Re: [R] find and replace characters in a string

2013-03-27 Thread Rui Barradas
Hello, The period is a metacharacter so you have to escape it. The period is escaped with a '\'. In it's turn, '\' is a metacharacter so it needs to be escaped. Hence the double'\\'. x <- "LOI ." gsub("\\.", "(%)", x) Hope

Re: [R] How to replace '$' sign?

2013-03-28 Thread Rui Barradas
Hello, Try gsub("[$,]", "", "$232,685.35436") Hope this helps, Rui Barradas Em 28-03-2013 15:39, Christofer Bogaso escreveu: Hello again, I want to remove "$" sign and replace with nothing in my text. Therefore I used following code: gsub("$|

Re: [R] changing y-axis intervals in a boxplot

2013-03-29 Thread Rui Barradas
Hello, You can use axis(side=2, at=c(10, 30, 50, 70, 90)) or axis(side=2, at=seq(10, 90, by = 20)) Hope this helps, Rui Barradas Em 29-03-2013 09:22, Berg, Tobias van den escreveu: Thank you Pascal but unfortunelately i still didn't figure out how to change the numbers presented at

Re: [R] Iterative regression through a series

2013-04-02 Thread Rui Barradas
rs in advance for (i in Time) { regr <- lm(Price[1:i] ~ Time[1:i]) estim[i] <- coef(regr)[2] if(is.na(coef(regr)[2])) error[i] <- NA else error[i] <- summary(regr)$coefficients[2,2] } Hope this helps, Rui Barradas Em 02-04-2013 17

Re: [R] Iterative regression through a series

2013-04-03 Thread Rui Barradas
<- lm(example$Price[1:i] ~ example$Time[1:i]) estim[i] <- coef(regr)[2] if(is.na(coef(regr)[2])) error[i] <- NA else error[i] <- summary(regr)$coefficients[2,2] } Hope this helps, Rui Barradas Em 03-04-2013 01:57, triskell4-umbre...@yahoo.fr escreveu:

Re: [R] place x-axis labels at bin edges in a histogram

2013-04-04 Thread Rui Barradas
Hello, Try the following. h <- hist(rnorm(100), xaxt = "n") axis(1, at = h$breaks) Hope this helps, Rui Barradas Em 04-04-2013 11:44, Shane Carey escreveu: Hi, I would like to places x-axis labels at the edge of bins on a histogram, i.e. the min value at first bin edge (l

Re: [R] retrieveing value from KS test

2013-04-05 Thread Rui Barradas
ned by ks.test. Hope this helps, Rui Barradas Em 05-04-2013 15:57, iritgur escreveu: Hi. how can i insert the value of p_value from KS.test into vector? Regards, Irit. -- View this message in context: http://r.789695.n4.nabble.com/retrieveing-value-from-KS-test-tp4663439.html Sent from the

Re: [R] manipulating R contingency tables

2013-04-06 Thread Rui Barradas
[-idx[, 1], -idx[, 2]] } Hope this helps, Rui Barradas Em 06-04-2013 07:55, Abhishek Pratap escreveu: Hi Guys I am back with another thing that's puzzling me. I am creating contingency tables but then I want to filter out certain columns and also find if any entry in the table

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread Rui Barradas
lt;- which(!is.na(x$mth))[1] x$mth <- x$mth[idx] x }) do.call(rbind, tmp) Hope this helps, Rui Barradas Em 06-04-2013 11:33, Leask, Graham escreveu: Dear List members I have a

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread Rui Barradas
Hello, Can't you post a data example? If your dataset is named 'dat' use dput(head(dat, 50)) # paste the output of this in a post Rui Barradas Em 06-04-2013 15:34, Leask, Graham escreveu: Hi Rui, Thank you for your suggestion which is very much appreciated. Unfortunatel

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread Rui Barradas
h <- x$mth[idx] x }) Rui Barradas Em 06-04-2013 18:12, Leask, Graham escreveu: Hi Arun, How odd. Directly pasting the code from your email precisely repeats the error. See below. Any thoughts on the cause of this anomaly? dput(head(dat,50)) structure(list(dn = c(4, 4, 4, 4, 4, 4,

Re: [R] Cannot scale data

2013-04-06 Thread Rui Barradas
Hello, Can't you simply call svm() with scale = FALSE ? If the variable is constant, it cannot be scaled to unit variance (and zero mean). Hope this helps, Rui Barradas Em 06-04-2013 17:19, Nicolás Sánchez escreveu: Hello! I have this error in R: In svm.default(x, y, scale =

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread Rui Barradas
Hello, With the attached file, I could reproduce the error but I think the added line does the trick. Rui Barradas Em 06-04-2013 19:20, arun escreveu: Hi, dat<- read.csv("test1.csv",sep=",",stringsAsFactors=FALSE) sp <- split(dat, list(dat$dn, dat$obs)) sp1<-

Re: [R] Data normalization

2013-04-06 Thread Rui Barradas
Hello, See ?scale scale(DATA) # mean 0, unit variance Hope this helps, Rui Barradas Em 06-04-2013 21:21, Beatriz González Domínguez escreveu: Dear all, I’m finding difficulties to normalize this data. Could you provide some input? DATA: c(0.000103113, 0.000102948, 0.000104001

Re: [R] R ecuatia error

2013-04-07 Thread Rui Barradas
Hello, What is the output of str(pg)? Is pg a data.frame? Rui Barradas Em 07-04-2013 14:14, catalin roibu escreveu: Dear all! I have a problem when I use this equation with R. mpr <- 843.75*exp(-1.119*pg) Error in FUN(left, right) : non-numeric argument to binary operator pg 01 02 03

Re: [R] Working with createFolds

2013-04-07 Thread Rui Barradas
7;s a numeric vector, folds$index$Fold_i[i] If it's a matrix, folds$index$Fold_i[i, j] If it's a list, folds$index$Fold_i[[i]] Hope this helps, Rui Barradas Em 07-04-2013 13:24, Nicolás Sánchez escreveu: Hello! I have a question. I am working with createFolds: folds<- trainContr

Re: [R] Boxplot Labels

2013-04-09 Thread Rui Barradas
os. This would allow for placement of the label near the point. p <- boxplot(dat1$ave, data= dat1, main= "Average Size", yaxt = "n") text(1, , y = max(dat1$ave), label = dat1$num[which.max(dat1$ave)], cex = .7, pos = 4) Hope this helps, Rui Barradas Em 09-04-2013 1

Re: [R] Boxplot Labels OK

2013-04-09 Thread Rui Barradas
Hello, The answers you had in another thread could lead you to bp <- boxplot(DATA$ave, data= DATA, main= "Average Size") idx <- which(DATA$ave %in% bp$out) text(x= bp$group, y= bp$out, labels= DATA$num[idx], cex = 0.7, pos = 4) Hope this helps, Rui Barradas Em 09-04-201

Re: [R] Boxplot Labels OK

2013-04-09 Thread Rui Barradas
Hello, I'm glad it help. You should cc the list, maybe it will be of use to others. Rui Barradas Em 09-04-2013 21:00, Beatriz González Domínguez escreveu: I have solved it, many thanks! -Original Message- From: Rui Barradas Sent: Tuesday, April 09, 2013 7:33 PM To: Beatriz Gon

Re: [R] log x-axis lables on a histogram

2013-04-10 Thread Rui Barradas
Hello, Try h <- hist(log10(rnorm(0:1000)), xaxt = "n") axis(1, at = pretty(h$breaks), labels = 10^pretty(h$breaks)) Hope this helps, Rui Barradas Em 10-04-2013 14:25, Shane Carey escreveu: Hi, If you have the following lets say: hist(log10(rnorm(0:1000))) How do you show

Re: [R] count by value

2013-04-10 Thread Rui Barradas
plit(test, qq), table) lapply(split(test, year %/% 10), table) Hope this helps, Rui Barradas Em 09-04-2013 19:45, catalin roibu escreveu: Hello all! I have a big problem now. I want a data frame like this: dput(head(test,100)) structure(c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N

Re: [R] how to calculate average of each column

2013-04-10 Thread Rui Barradas
grp <- rep(1:(1 + nrow(dat) / 60), each = 60)[seq_len(nrow(dat))] do.call(rbind, lapply(split(dat, grp), colMeans)) Hope this helps, Rui Barradas Em 10-04-2013 18:46, Ye Lin escreveu: Hey All, I have a large dataset and I want to calculate the average of each column then return a new dataset.

Re: [R] Optimization problem

2013-04-10 Thread Rui Barradas
this helps, Rui Barradas Em 10-04-2013 19:33, nntx escreveu: Thank you professor. I think the minimum value of x^2 between -1 and 1 should be x=0, y=0. but the result is not that. I am thinking is any wrong with my thought? Thanks for helping me out! -- View this message in context: htt

Re: [R] Optimization problem

2013-04-11 Thread Rui Barradas
y the following function is.zero <- function(x, eps = .Machine$double.eps^0.5) abs(x) < eps is.zero(your_value) # TRUE? Or even try ?all.equal all.equal(your_value, 0) Hope this helps, Rui Barradas Em 10-04-2013 22:13, nntx escreveu: Rui, thanks for your reply. You meant that it is

Re: [R] %*%

2013-04-11 Thread Rui Barradas
Hello, Just try ?"%*%" And the hel page title will give you the answer. Hope this helps, Rui Barradas Em 11-04-2013 11:25, Shane Carey escreveu: What does these operators do: %*% Thanks __ R-help@r-project.org mailing

Re: [R] group data

2013-04-11 Thread Rui Barradas
Hello, Try the following. dat <- read.table(text = " ID Value AL1 1 AL2 2 CA1 3 CA4 4 ", header = TRUE, stringsAsFactors = FALSE) dat$State <- substr(dat$ID, 1, 2) Note that this dependes on having State being defined by the first two characters of ID. Hope this help

Re: [R] Reshaping Data for bi-partite Network Analysis

2013-04-13 Thread Rui Barradas
Hello, With the following the order of both rows and columns will be different than the order of your example output, but the table is basically the same. xtabs(time ~ people + place, data = Input) Hope this helps, Rui Barradas Em 13-04-2013 22:03, sylvain willart escreveu: Hello I have

Re: [R] Aggregate function Bagging

2013-04-14 Thread Rui Barradas
Hello, If you run the example in ?bag you can type data(BloodBrain) ctreeBag$aggregate at an R prompt to see an example aggregate function. Note that it dos _not_ have the parenthesis. Hope this helps, Rui Barradas Em 14-04-2013 11:31, Nicolás Sánchez escreveu: Good morning all. I am

Re: [R] Create New Column Inside Data Frame for Many Data Frames

2013-04-14 Thread Rui Barradas
[i]][["Rate"]] <- ROC(lst[[i]][["population"]]) } Hope this helps, Rui Barradas Em 14-04-2013 18:19, Sparks, John James escreveu: Dear R Helpers, I have a large number of data frames and I need to create a new column inside each data frame. Because there is a large numb

Re: [R] use of simulate.Arima (forecast package)

2013-04-16 Thread Rui Barradas
sim = 48), col = "red") Hope this helps, Rui Barradas Em 15-04-2013 15:13, Stefano Sofia escreveu: I would like to simulate some SARIMA models, e.g. a SARIMA (1,0,1)(1,0,1)[4] process. I installed the package 'forecast', where the function simulate.Arima should do what I a

Re: [R] I don't understand the 'order' function

2013-04-16 Thread Rui Barradas
210, 210, 505, 1045) (o <- order(x) ) x[o] # Allright Hope this helps, Rui Barradas Do I have a damaged version of R? I became still more astonished when I used the sort function and got the right answer: sort(c(2465, 2255, 2085, 1545, 1335, 1210, 920, 210, 210, 505, 1045)) [1] 21

Re: [R] efficiently diff two data frames

2013-04-16 Thread Rui Barradas
function(A, B){ f <- function(X, Y) !duplicated(rbind(Y, X))[nrow(Y) + 1:nrow(X)] ix1 <- f(A, B) ix2 <- f(B, A) ix1 & ix2 } ix <- setdiffDF2(Xe, Xf) Xe[ix,] Xf[ix,] Note that this gives no information on the columns. Hope this helps, Rui Barradas Em 16-

Re: [R] Creating a vector with repeating dates

2013-04-17 Thread Rui Barradas
Hello, Try the following. rep(c("Current_date", as.character(df$dates)), 3) Hope this helps, Rui Barradas Em 17-04-2013 10:11, Katherine Gobin escreveu: Dear R forum I have a data.frame df = data.frame(dates = c("4/15/2013", "4/14/2013", "4/13/2013&quo

Re: [R] Best way to calculate averages of Blocks in an matrix?

2013-04-17 Thread Rui Barradas
Hello, Try the following. blocks <- rep(1:(1 + nrow(sim_sub) %/% 5), each = 5)[seq_len(nrow(sim_sub))] aggregate(sim_sub, list(blocks), FUN = mean) Hope this helps, Rui Barradas Em 17-04-2013 18:04, arun escreveu: do.call(rbind,lapply(split(sim_sub,((seq_len(nrow(sim_sub))-1)%/% 5

Re: [R] dividing a long column to many short ones by a condition

2013-04-18 Thread Rui Barradas
Hello, Something like this? grp <- cumsum(abs(c(0, diff(x == 0 tmp <- lapply(split(x, grp), function(x) if(all(x == 0)) NULL else x) tmp[sapply(tmp, function(x) !is.null(x))] Hope this helps, Rui Barradas Em 18-04-2013 10:33, Igor Mintz escreveu: hello i have a very long col

Re: [R] dividing a long column to many short ones by a condition

2013-04-18 Thread Rui Barradas
quot;) x grp <- cumsum(abs(c(0, diff(x == 0 tmp <- lapply(split(x, grp), function(x) if(all(x == 0)) NULL else x) tmp[sapply(tmp, function(x) !is.null(x))] Rui Barradas Em 18-04-2013 12:24, Rui Barradas escreveu: Hello, Something like this? grp <- cumsum(abs(c(0, diff(x == 0

Re: [R] how to subtotal by rows

2013-04-19 Thread Rui Barradas
1996 NANA 7 ", header = TRUE) aggregate(as.matrix(dat[, 3:5]), by = list(dat$year, dat$fid), FUN = sum, na.rm = TRUE) Hope this helps, Rui Barradas Em 19-04-2013 16:59, shyam basnet escreveu: Dear R-users, I have a dataset as like below, and I want to subtot

Re: [R] how to subtotal by rows

2013-04-19 Thread Rui Barradas
Hello, You don't need as.matrix(), the following will do. aggregate(dat[, 3:5], by = list(dat$year, dat$fid), FUN = sum, na.rm = TRUE) Rui Barradas Em 19-04-2013 20:24, Rui Barradas escreveu: Hello, Try the following. dat <- read.table(text = " fid year rice whe

Re: [R] how to set the row name of a specific row

2013-04-20 Thread Rui Barradas
Hello, It is possible, but do the other rows have names? x <- matrix(1:12, 4) x <- rbind(x, c(13:15)) rownames(x)[5] <- "abcd" x Hope this helps, Rui Barradas Em 20-04-2013 10:58, Simone Gabbriellini escreveu: Hello, I am adding rows to a matrix using rbind() and I wou

Re: [R] Source Code

2013-04-20 Thread Rui Barradas
xternal.graphics(C_text, xy.coords(x, y, recycle = TRUE), labels, adj, pos, offset, vfont, cex, col, font, ...) invisible() } Hope this helps, Rui Barradas Em 20-04-2013 23:38, Eva Prieto Castro escreveu: This is what I get when typing text: text function (x, ...) UseMethod("

Re: [R] How to set frequncy?

2013-04-22 Thread Rui Barradas
Hello, If stock prices are daily data, use frequency = 1. Hope this helps, Rui Barradas Em 21-04-2013 14:22, Lizhu Ren escreveu: Hi Boss, i have data of one stock price from 2 January 2006 to 31 December 2012.But each year had different markert day, I want to calculate daily returns and

Re: [R] How to set frequncy?

2013-04-22 Thread Rui Barradas
Hello, You've not Cc'ed the list If you keep the discussion on the list, you'll have more and better answers. See the post by Michael Weylandt for a more complete answer to your question. Rui Barradas Em 22-04-2013 12:16, Lizhu Ren escreveu: > thanks for u replying, &g

<    10   11   12   13   14   15   16   17   18   19   >