Re: [R] Refer to previous row

2013-01-07 Thread Rui Barradas
Hello, Try the following. dat$X3 <- c(0L, dat$ID[-1] <= dat$ID[-nrow(dat)]) Hope this helps, Rui Barradas Em 07-01-2013 13:33, Paolo Donatelli escreveu: Hi all, I have a very basic doubt -- but still, I am a newby! My question is about referring to the previous row: in a sample

Re: [R] renumber a list of numbers

2013-01-07 Thread Rui Barradas
Hello, I'm not sure I understand. Do you want to renumber column Event_name starting at 1? If so the following does the job. dat$Event_name <- dat$Event_name - min(dat$Event_name) + 1 Hope this helps, Rui Barradas Em 07-01-2013 16:41, Charles Determan Jr escreveu: Greetings R user

Re: [R] Using objects within functions in formulas

2013-01-09 Thread Rui Barradas
;- paste("(1|", names(w2), ")", collapse=" + ", sep="") p2 <- paste("y2 ~ x2 +" , p1) form = as.formula(p2) m1 = glmer(form, data = w2) return(m1) } Hope this helps, Rui Barradas Em 09-01-2013 16:53, Aidan MacNamara escreveu

Re: [R] how to generate a matrix by an my data.frame

2013-01-10 Thread Rui Barradas
tri(mat1, diag = TRUE)] <- dat$value mat2 <- matrix(0, nrow = 53, ncol = 53) # initialize with zeros mat2[upper.tri(mat2, diag = TRUE)] <- dat$value Hope this helps, Rui Barradas Em 10-01-2013 15:21, Yao He escreveu: > Dear All > > It is a little hard to give a good small

Re: [R] sort matrix based on a specific order

2013-01-10 Thread Rui Barradas
Hello, Try the following. order() gives you a permutation of the vector 'ind' and to order that permutation gives its inverse. mat <- cbind(c('w','x','y','z'),c('a','b','c','d')) ind <- c('c&#x

Re: [R] transparency in segments()

2013-01-10 Thread Rui Barradas
Hello, You can use ?rgb to set the transparency level. As an example, with alpha = 0.5 clr <- c(rgb(1, 0, 0, 0.5), rgb(0, 0, 1, 0.5)) plot(0:1, 0:1, col = clr[1], lwd = 10, type = "l") lines(0:1, 1:0, col = clr[2], lwd = 10) Hope this helps, Rui Barradas Em 10-01-2013 21:29,

Re: [R] Merging list of dataframes with reshape merge_all

2013-01-11 Thread Rui Barradas
, col2=11:20, col3=21:30, Y = rnorm(10)) merge_all(list(df1, df2), by=c("col1","col2","col3"), all.x=TRUE, all.y=TRUE) # No Y column merge(df1, df2, by=c("col1","col2","col3"), all.x=TRUE, all.y=TRUE) Contact the package maintainer fo

Re: [R] Mean according to the combination of two factors

2013-01-11 Thread Rui Barradas
Hello, Try the following. # make up some data dat <- data.frame(values = rnorm(100), experiment = sample(10, 100, TRUE), composite = sample(17, 100, TRUE)) aggregate(values ~ experiment + composite, data = dat, FUN = mean) Hope this helps, Rui Barradas Em 11-01-2013 23:26, li li escre

Re: [R] How to extract value for specific rows in an array?

2013-01-12 Thread Rui Barradas
40.3 18442.0429 35.1 18443.0030 16.5 ", header = TRUE) agg <- aggregate(Depth ~ Day, data = dat, FUN = max) merge(agg, dat) Hope this helps, Rui Barradas Em 12-01-2013 05:32, fjaine escreveu: Hi everyone, I have a dataset that contains depths measu

Re: [R] Drawing a dotted circle.

2013-01-12 Thread Rui Barradas
tugal.1252 LC_CTYPE=Portuguese_Portugal.1252 [3] LC_MONETARY=Portuguese_Portugal.1252 LC_NUMERIC=C [5] LC_TIME=Portuguese_Portugal.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.15.2 Hope this h

Re: [R] Drawing a dotted circle.

2013-01-12 Thread Rui Barradas
LTY_SOLID; So, the op is out of luck, lty solid is hard-coded in the C source. Maybe plotrix::draw.circle, like Jose suggested. Rui Barradas Em 12-01-2013 18:53, Ben Bolker escreveu: A wild guess which I can't check right now, but: is there something funny/different with the Windows

Re: [R] Code to fetch summary info from vector

2013-01-15 Thread Rui Barradas
- tapply(b, groups, FUN = max) mx[mx > 1] # And you can combine both like in cbind(length = r$lengths[r$values], max = mx[mx > 1]) Hope this helps, Rui Barradas Em 15-01-2013 16:57, Jessica Streicher escreveu: Maybe rle can help a little here rle(b>1) Run Length Encoding length

Re: [R] function approx interpolation of time series data sets

2013-01-16 Thread Rui Barradas
, format = "%H:%M:%S")) Hope this helps, Rui Barradas Em 16-01-2013 08:52, e-letter escreveu: Readers, Am trying to use the function 'approx' to interpolate time series data sets: data1: 01:23:40 5 01:23:45 10 01:23:50 12 01:23:55 7 data2: 01:23:42 01:23:47 01:23:51 01:

Re: [R] read tab delimited file from a certain line

2013-01-16 Thread Rui Barradas
it i <- grep("^year", x) read.table(textConnection(x[i:length(x)]), header = TRUE) Hope this helps, Rui Barradas Em 16-01-2013 14:17, Christof Kluß escreveu: Hi I would like to read table data from a text-files with extra informations in the header (of unknown line count). Examp

Re: [R] Mean calculation by two variables

2013-01-16 Thread Rui Barradas
pecie + Food.item, data = ex, FUN = mean) Hope this helps, Rui Barradas Em 16-01-2013 15:41, Raoni Rodrigues escreveu: > Hello All, > > I have a data frame (dput information below) with food item weight for fish > species. > > I need to calculate the Mean proportion by weigh

Re: [R] Recursive file Download from FTP

2013-01-16 Thread Rui Barradas
ames, "\r\n")) # To download the files destdir <- "C:/Rui/Temp/" # Adapt to your system lapply(fn, function(x) download.file(paste0(url, x), paste0(destdir, x))) Hope this helps, Rui Barradas Em 16-01-2013 22:41, Peter Maclean escreveu: > > I want to download

Re: [R] exporting simulated data

2013-01-17 Thread Rui Barradas
uot;,sep="") #save data write(someData,filename) } This would make unique filenames but not quite what you wanted. For this maybe filename <- sprintf("data%04d.dat", i) Hope this helps, Rui Barradas greetings, Jessi On 17.01.2013, at 04:31, Ray Cheung wrote:

Re: [R] How can i keep only latest entries?

2013-01-17 Thread Rui Barradas
Hello, Try the following. (I've named your data.frame 'dat') do.call(rbind, lapply(split(dat, dat$`No.`), tail, 1)) Hope this helps, Rui Barradas Em 17-01-2013 10:50, Mat escreveu: Hello togehter, i have a data.frame like this one: No. Date last chang

Re: [R] plotting from dataframes

2013-01-18 Thread Rui Barradas
Hello, Maybe instead of a loop, you could try lapply(frames, function(y) plot(y$hour1)) Hope this helps, Rui Barradas Em 18-01-2013 09:16, condor escreveu: So by hand the command would be par(mfrow=c(1,2)) plot(frames$'1'hour1) plot(frames$'2'hour1) But in my case the

Re: [R] function approx interpolation of time series data sets

2013-01-18 Thread Rui Barradas
1:23:59 ") approx(as.POSIXct(data1$V1, format = "%H:%M:%S"), y = data1$V2, xout = as.POSIXct(data2$V1, format = "%H:%M:%S")) Note that the last two values of data2 are outside the range of data1, and therefore the interpolation functions return nothing (zoo::na.

Re: [R] columns called X rename Y

2013-01-18 Thread Rui Barradas
Hello, Try the following. names(seba)[grep("numbers", names(seba))] <- "b" names(seba)[grep("constant", names(seba))] <- "c" names(seba) Hope this helps, Rui Barradas Em 18-01-2013 18:14, Sebastian Kruk escreveu: I have a data. frame to which

Re: [R] Working with regular expression

2013-01-18 Thread Rui Barradas
Hello, This one seems to work. gsub("[[:alpha:]_]*(.*)", "\\1", Text) Hope this helps, Rui Barradas Em 18-01-2013 20:11, Christofer Bogaso escreveu: Hello again, I was trying to extract the date element from a character vector using Regular expression. Below is a samp

Re: [R] select rows with identical columns from a data frame

2013-01-18 Thread Rui Barradas
Hello, Try the following. complete.cases(f) & apply(f, 1, function(x) all(x == x[1])) Hope this helps, Rui Barradas Em 18-01-2013 20:53, Sam Steingold escreveu: I have a data frame with several columns. I want to select the rows with no NAs (as with complete.cases) and all col

Re: [R] Working with regular expression

2013-01-18 Thread Rui Barradas
Hello, Right, thanks for the explanation, it saved me time. Rui Barradas Em 18-01-2013 22:50, David Alston escreveu: Greetings! I hope you don't mind, Rui Barradas, but I'd like to explain the regex. Parsing it was a fun exercise! Here's the regex broken

Re: [R] Tinn-R and R problem

2013-01-19 Thread Rui Barradas
Hello, This seems to be a Tinn-R question, to be addressed to its team, not to R-Help. Anyway, since you're using R 2.12.1, maybe the error goes away if you update your version of R. Hope this helps, Rui Barradas Em 19-01-2013 04:30, Roslina Zakaria escreveu: Dear r-users, Actually,

Re: [R] Regex for ^ (the caret symbol)?

2013-01-21 Thread Rui Barradas
^] it doesn't need to be escaped. grep("[a^]", c("a^", "and", "b", "^")) # 1 2 4 Rui Barradas Duncan Murdoch --- Jeff NewmillerThe .

Re: [R] Assistant

2013-01-22 Thread Rui Barradas
2.32632108817696, 3.60844436009277, : initial value in 'vmmin' is not finite So revise the way you call fitdistr and then, if the error persists, revise the parametric distribution to be fitted. Hope this helps, Rui Barradas Em 22-01-2013 16:07, Adelabu Ahmmed escreveu: Good-day Sir,

Re: [R] extracting characters from a string

2013-01-23 Thread Rui Barradas
Hello, Try the following. fun <- function(x, sep = ", "){ s <- unlist(strsplit(x, sep)) regmatches(s, regexpr("[[:alpha:]]*", s)) } fun(pub) Hope this helps, Rui Barradas Em 23-01-2013 17:38, Biau David escreveu: Dear All, I have a data frame

Re: [R] extracting characters from a string

2013-01-23 Thread Rui Barradas
m <- lapply(x, function(y) gregexpr(" [[:alpha:]]*$", y)) res <- lapply(seq_along(x), function(i) regmatches(x[[i]], m[[i]], invert = TRUE)) res <- lapply(res, unlist) lapply(res, function(y) y[nchar(y) > 0]) } fun2(pub) Hope this h

Re: [R] From table to data.frame

2013-01-24 Thread Rui Barradas
Hello, try the following. test.df$Var1 <- seq(0,1, by=0.05)[-1] test.df Hope this helps, Rui Barradas Em 24-01-2013 17:39, Wim Kreinen escreveu: Hello, I have a dataframe (test.df) with intervals that were generated by table (see below). I would prefer a dataframe labeled like t

Re: [R] how should I make the optional arguments in r?

2013-01-24 Thread Rui Barradas
Hello, The question is a bit confusing, but for what I could understand, try changing to rr <- getrange(dataw, mydatao, method = method) Hope this helps, Rui Barradas Em 24-01-2013 18:26, Tammy Ma escreveu: HI, I guess I did sth wrong with the optional argument in the program. bu

Re: [R] functions as arguments to ther functions with inlinedocs

2013-01-24 Thread Rui Barradas
t;- dummyfunction() # this creates the default function f(x) g <- dummyfunction(mean) # this creates another function g(x) As you can see, you can use default functions as arguments in your function declaration. Hope this helps, Rui Barradas Em 24-01-2013 18:32, Jannis escreveu: Dear R

Re: [R] functions as arguments to ther functions with inlinedocs

2013-01-24 Thread Rui Barradas
Hello, Sorry, it's RIGHT parenthesis. Rui Barradas Em 24-01-2013 18:54, Rui Barradas escreveu: Hello, Your function declaration has a syntax error, one left parenthesis too much. Corrected it would be dummyfunction <- function(filters = function(x) {b = 0; x > b} ){ # rest o

Re: [R] Custom axis with months name

2013-01-24 Thread Rui Barradas
Hello, To get the months names you can try format(data[,1], "%B") As for the axis, see the help page ?axis. Argument 'labels'. Hope this helps, Rui Barradas Em 24-01-2013 17:34, Grigory Fateyev escreveu: Hello! I have data.frame with column class POSIXct: data[, 1

Re: [R] Question on matrix calculation

2013-01-24 Thread Rui Barradas
Hello, Something like this? do.call(rbind, lapply(split(as.data.frame(mat), match_df$criteria), colSums)) Hope this helps, Rui Barradas Em 24-01-2013 19:39, Christofer Bogaso escreveu: Hello again, Ley say I have 1 matrix and 1 data frame: mat <- matrix(1:15, 5) match_df <- data

Re: [R] how to delete the null elements in list

2013-01-25 Thread Rui Barradas
Hello, Try the following. suu <- list(NULL, NULL, 1:2, matrix(1:4, 2)) suu[!sapply(suu, is.null)] Hope this helps, Rui Barradas Em 25-01-2013 12:31, Tammy Ma escreveu: HI, I have the list: suu [[1]] NULL [[2]] NULL [[3]] item_id prod 1 2 [[4]] item_id pro

Re: [R] joint probability distribution

2013-01-25 Thread Rui Barradas
so try kernel density estimates: library(sos) findFn('kde') Hope this helps, Rui Barradas Em 25-01-2013 18:13, eliza botto escreveu: Dear R family, I want to calculate the joint probability (distribution) of two random continuous variables X and Y. Could to please tell me how to

Re: [R] Loops

2013-01-27 Thread Rui Barradas
<- paste0("fa", 1:5, "b") Hope this helps, Rui Barradas Em 27-01-2013 08:02, Francesca escreveu: Dear Contributors, I am asking help on the way how to solve a problem related to loops for that I always get confused with. I would like to perform the following procedure in

Re: [R] Converting column of strings to boolean

2013-01-27 Thread Rui Barradas
Hello, Something like this? x <- sample(c("red", "blue", "green", "yellow"), 100, replace = TRUE) cnames <- unique(x) sapply(cnames, function(.x) x == .x) Hope this helps, Rui Barradas Em 26-01-2013 22:25, domcastro escreveu: Hi I'm t

Re: [R] scan not working

2013-01-27 Thread Rui Barradas
pt to your needs. Instead of 'suf', I've used option '--ext' for 'extension'. Change to fit your taste. Hope this helps, Rui Barradas Em 27-01-2013 17:27, Emily Sessa escreveu: Hello all (again), I received a very helpful answer to this question, and wou

Re: [R] Pivot

2013-01-29 Thread Rui Barradas
want a matrix you can do it with cn <- paste(names(dimnames(xt))[2], dimnames(xt)[[2]], sep = ".") xt <- cbind(xt) colnames(xt) <- cn xt Hope this helps, Rui Barradas Em 28-01-2013 23:48, farnoosh sheikhi escreveu: Hi, I have a data set as follow: X Z x1102 x2

Re: [R] Can I define a object array in R?

2013-01-29 Thread Rui Barradas
Hello, You can store any kind of objects in a list. More or less like the following. tlist <- vector("list", 100) n <- 10 tlist[[n]] <- C5.0(...) Hope this helps, Rui Barradas Em 29-01-2013 07:01, cuiyan escreveu: Here is my problem, 100 decision trees were buil

Re: [R] centering matrix

2013-01-29 Thread Rui Barradas
Hello, The question is a bit confusing. If you nedd to compute B = X'X, all you have to do is B <- t(X) %*% X If you want to compute the other formula, the following avoids loops. n <- nrow(d) B <- -d^2/2 - rowSums(d^2)/n - colSums(d^2)/n + sum(d^2)/n^2 Hope this helps, Rui B

Re: [R] A question about R

2013-01-29 Thread Rui Barradas
Hello, Though I don't have Windows 8 installed yet, this question was already asked to R-Help and the answer was yes, it does. Hope this helps, Rui Barradas Em 29-01-2013 13:57, Chia-Chieh Lin escreveu: Hi, I was wondering whether R works on Windows 8? Many thanks. Chia-Chie

Re: [R] centering matrix

2013-01-29 Thread Rui Barradas
Hello, Please keep the discussion on the R-Help list, there's no reason not to. As for your question, can you be more specific? Also, take a look at function ?scale. Rui Barradas Em 29-01-2013 23:31, Eleonora Schiano escreveu: i have to do multidimensional scaling. Can you help me? 2

Re: [R] Integration of mixed normal distribution

2013-01-30 Thread Rui Barradas
sd2) - pnorm(x1, mean, sd2) p1*p + p2*(1 - p) } integrate(fun, 0, 1, mean = 0, sd1 = 1, sd2 = 2, p = 0.5) fun2(0, 1, mean = 0, sd1 = 1, sd2 = 2, p = 0.5) Hope this helps, Rui Barradas Em 30-01-2013 09:19, Johannes Radinger escreveu: Hi, I already found a conversation on the inte

Re: [R] remove label from specific axis

2013-01-30 Thread Rui Barradas
Hello, Just use ylab = "". Hope this helps, Rui Barradas Em 30-01-2013 13:33, e-letter escreveu: Readers, For a graph plot instruction: plot(seq(10:50),type='h',yaxt='n',yaxs='i',lab=c(20,2,2),xlab='x axis label',bty='l',main=&#

Re: [R] Percentages in bar plot

2013-01-30 Thread Rui Barradas
Hello, Try barplot(table(stop)/sum(table(stop))) Hope this helps, Rui Barradas Em 30-01-2013 11:34, Naser Jamil escreveu: Dear R-users, Though it's a silly thing to ask, but I'm not getting a way out. I wish to find the percentage distribution for a data vector 'stop'.

Re: [R] Help with multiple barplots

2013-01-31 Thread Rui Barradas
like this: lapply(c("gender", "age"), function(y) { lapply(c("guns", "crime", "climate"), function(x) barplot(prop.table(table(dat[[x]], dat[[y]]), 2)))}) Hope this helps, Rui Barradas Em 31-01-2013 15:42, Simon Kiss escr

Re: [R] ks.test and wilcoxon.test results differ from other stat.packages

2013-02-01 Thread Rui Barradas
on of ?ks.test. See also the references there, such as Marsaglia, Tsang, Wang (2003) http://www.jstatsoft.org/v08/i18/ Hope this helps, Rui Barradas Em 01-02-2013 11:24, Meyners, Michael escreveu: Impossible to say w/o a reproducible example, but to start with let me suggest looking at the

Re: [R] Loading a list into the environment

2013-02-01 Thread Rui Barradas
Hello, Something like this? myfun <- function(x, envir = .GlobalEnv){ nm <- names(x) for(i in seq_along(nm)) assign(nm[i], x[[i]], envir) } myvariables <- list(a=1:10,b=20) myfun(myvariables) a b Hope this helps, Rui Barradas Em 01-02-2013 22:24,

Re: [R] create and save a simulated dataset

2013-02-02 Thread Rui Barradas
# trees per stand lapply(1:10, function(i) runif(sample(max.trees, 1), min.diam, max.diam)) Hope this helps, Rui Barradas Em 02-02-2013 20:10, Giovanna Ottaviani escreveu: Hello, I am trying to learn how to create a simulated dataset of a forest stand: I must simulate 10 stands, for each of the stands

Re: [R] vectorisation

2013-02-02 Thread Rui Barradas
][mm[,i]] <- 1; s2[,i]}) identical(s2, starts) # TRUE Note that lapply is a loop in disguise. Hope this helps, Rui Barradas Em 02-02-2013 16:38, Brett Robinson escreveu: Hi I'm trying to set up a simulation problem without resorting to (m)any loops. I want to set entries in a data f

Re: [R] Script for conditional sums of vectors

2013-02-04 Thread Rui Barradas
Hello, In what follows, I've renamed the data.frame 'dat', 'data' already is an R function. xtabs(c ~ a + b, data = dat) Hope this helps, Rui Barradas Em 04-02-2013 09:29, Benjamin Gillespie escreveu: Hi guys, I hope you can help me with this (probably) sim

Re: [R] If() values in one dataframe then return values from another

2013-02-04 Thread Rui Barradas
Hello, Try the following. mA <- sapply(seq_len(nrow(data1)), function(i) if(any(data1[i,] == 3)) meter[i, 1] else NA) Hope this helps, Rui Barradas Em 04-02-2013 17:48, Steven Ranney escreveu: I have a large data frame ("data1") that looks like: A1 A2 A3 A4 A5 A6

Re: [R] Exponentiate very large numbers

2013-02-04 Thread Rui Barradas
e this helps, Rui Barradas Em 04-02-2013 15:11, francesca casalino escreveu: Dear R experts, I have the logarithms of 2 values: log(a) = 1347 log(b) = 1351 And I am trying to solve this expression: exp( ln(a) ) - exp( ln(0.1) + ln(b) ) But of course every time I try to exponentiate the log

Re: [R] Exponentiate very large numbers

2013-02-04 Thread Rui Barradas
Sorry, it should be: Divide both terms by exp(log(0.1) + log.b) to give tmp1 <- exp(log.a - log(0.1) - log.b) - 1 result <- tmp1 * exp(log(0.1) + log.b) Rui Barradas Em 04-02-2013 18:53, Rui Barradas escreveu: Hello, Use a simple transfomation. Divide both t log.a <- 1347 log.

Re: [R] duplicate data

2013-02-05 Thread Rui Barradas
Hello, To average the values of z in case of duplicated x and y, you can use s2 <- aggregate(z ~ x + y, data = sorpe, FUN = mean) Hope this helps, Rui Barradas Em 05-02-2013 07:06, Richard Müller escreveu: Hello, I have a long list of x-, y- and z-data and try to generate a heat

Re: [R] how to draw confidence interval lines of a fitted curve of polynominal regression

2013-02-07 Thread Rui Barradas
ta and the fitted line plot(x, y) lines(x, fitted[, "fit"]) # now the confidence bands lines(x, fitted[, "lwr"], lty = "dotted") lines(x, fitted[, "upr"], lty = "dotted") Hope this helps, Rui Barradas Em 07-02-2013 01:31, Elaine Kuo escreveu: H

Re: [R] spatstat kstest

2013-02-07 Thread Rui Barradas
Hello, Try the following. > maintainer("spatstat") [1] "Adrian Baddeley " Hope this helps, Rui Barradas Em 07-02-2013 02:05, Hiroshi Saito escreveu: Dear sir, Which mailing list is appropriate to ask for kstest in spatstat? Regards, Hiroshi Saito

Re: [R] combining dataframes into single df with all columns

2013-02-07 Thread Rui Barradas
Hello, The following function will give what you seem to want. fun <- function(x, y){ df3 <- x df3 <- cbind(df3, df2[setdiff(names(y), names(x))]) df3[order(names(df3))] } fun(df1, df3) Hope this helps, Rui Barradas Em 07-02-2013 18:36, Anika Masters escr

Re: [R] combining dataframes into single df with all columns

2013-02-07 Thread Rui Barradas
Hello, Sorry, there's a bug in my first reply. Corrected: fun <- function(x, y){ df3 <- cbind(x, y[setdiff(names(y), names(x))]) df3[order(names(df3))] } fun(df1, df2) Rui Barradas Em 07-02-2013 19:16, Rui Barradas escreveu: Hello, The following function will gi

Re: [R] help with double looping

2013-02-08 Thread Rui Barradas
Hello, Maybe seq(1, 16*11, 11)? (16*11 is 176, not 166) Hope this helps, Rui Barradas Em 08-02-2013 16:03, christel lacaze escreveu: hi there, I have a dataframe in the shape vA1, vA2,..., vA11, vB1, vB2,..., VB11,..., VP1, VP2,, VP11 (so 16 times a sequence of 11 variables) I am

Re: [R] Can not melt data.frame

2013-02-08 Thread Rui Barradas
Hello, The id.vars must "be integer (variable position) or string (variable name)" (from the help page ?melt.data.frame) This seems to work. myd <- mydata myd$date <- as.character(myd$date) melt(myd, id.vars = c("date")) Hope this helps, Rui Barradas Em 0

Re: [R] help with double looping

2013-02-08 Thread Rui Barradas
Hello, You're right, sorry for the misleading tip. How about seq(1, 177, 11)? Please note that without a data example, it's not very easy to say. Can't you post a small dataset using ?dput dput(head(data, 20)) # paste the output of this. Rui Barradas Em 08-02-2013 17:10,

Re: [R] aggregation-type question

2013-02-08 Thread Rui Barradas
a 5 0.675868776 0.7721177 a 6 0.008465241 0.5046486 a ", header = TRUE) str(dat) lapply(split(dat[, c("x", "y")], dat$group), cor) lapply(split(dat[, c("x", "y")], dat$group), function(d) cor(d$x, d$y)) Hope this helps, Rui Barradas Em 08-02-2

Re: [R] assign estimated values

2013-02-11 Thread Rui Barradas
" "ma1" "intercept" .. ..$ : chr [1:3] "ar1" "ma1" "intercept" $ lag :List of 2 ..$ ar: int 1 ..$ ma: int 1 $ convergence : int 0 $ include.intercept: logi TRUE - attr(*, "class")= chr "arma" mod$

Re: [R] convert 12 time stamp to 24 hour

2013-02-11 Thread Rui Barradas
Hello, You're trying to plot the df, not the column. Try plot(testdata ~ testtimedataset$V1) Hope this helps, Rui Barradas Em 11-02-2013 13:30, e-letter escreveu: Readers, Have since tried to plot converted 24 hour data: testtimedataset V1 1 13:01:41 2 13:02:10 3 13:02:38

Re: [R] Changing the order of months within a year

2013-02-12 Thread Rui Barradas
uot;, "Nov", "Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug")) y <- sapply(sp, `[`, 2) order(y, m) } idx <- fun(dat$date) dat[idx, ] Hope this helps, Rui Barrad

Re: [R] subsetting data file by intoducing a second file

2013-02-12 Thread Rui Barradas
Hello, Read the help page ?subset more carefully, it's argument 'select' you should be using: subset(bg, select = c_bg) Hope this helps, Rui Barradas Em 12-02-2013 14:29, Ozgul Inceoglu escreveu: Hello, I have a very data matrix and I have a file which has the names

Re: [R] Max value of each 2 rows in dataframe

2013-02-12 Thread Rui Barradas
Hello, Your data example is a mess. Can't you please use ?dput to post it? Supposing your data is named 'dat', use dput(head(dat, 20)) # Paste the output of this in a post Hope this helps, Rui Barradas Em 12-02-2013 15:30, zuzana zajkova escreveu: Hello, I would like

Re: [R] match in dependence of 2 columns

2013-02-13 Thread Rui Barradas
= TRUE) Hope this helps, Rui Barradas Em 13-02-2013 14:39, Mat escreveu: Hello, i want to match a column of one data.frame to another, my problem is, that i only want to match the data, if 2 columns are equal. i have a example: data.frame1 cu.nr. name

Re: [R] e1071::skewness and psych::skew return NaN

2013-02-13 Thread Rui Barradas
Hello, That value means that some values of your data are negative or zero. A simple inspection shows that any(dat < 0) # FALSE any(dat == 0) # TRUE Solution: don't log your data Hope this helps, Rui Barradas Em 13-02-2013 16:55, Stephen Politzer-Ahles escreveu: Hello everyon

Re: [R] e1071::skewness and psych::skew return NaN

2013-02-13 Thread Rui Barradas
Hello, Just remembered, you can see how many values are zero, and since it's only one value, remove it and log the rest. sum(dat == 0) # 1 d2 <- dat[dat != 0] library(psych) skew(log(d2)) [1] 0.6089985 Hope this helps, Rui Barradas Em 13-02-2013 17:59, Rui Barradas escreveu

Re: [R] match in dependence of 2 columns

2013-02-14 Thread Rui Barradas
Hello, You can do something like this: join(dat1, dat2[, c("cu.nr", "name", "value")], by=c("cu.nr.","name"),type="right") Hope this helps, Rui Barradas Em 14-02-2013 07:03, Mat escreveu: thank you, this code works: library(p

Re: [R] approxfun values

2013-02-14 Thread Rui Barradas
30 5 4 40 7 5 50 NA 6 60 NA 7 70 2 8 80 6 9 90 9 10 100 NA ", header = TRUE) f <- approxfun(dat) x <- dat$V1[is.na(dat$V2)] y <- f(x) y Hope this helps, Rui Barradas Em 14-02-2013 08:43, e-letter escreveu: Readers, According to the help '?approxfu

Re: [R] Looking for an easy way to change the names of a vector

2013-02-14 Thread Rui Barradas
Hello, Use ifelse, and assign its values to names(Data) ifelse(grepl(" ", names(Data)), gsub(" ", "-", names(Data)), paste0(names(Data), "-XXX")) Hope this helps, Rui Barradas Em 14-02-2013 11:43, Christofer Bogaso escreveu: Hello again,

Re: [R] appending data to a row

2013-02-14 Thread Rui Barradas
108 9 ", header = TRUE) dat$timevar <- rep(1:2, nrow(dat)/2) reshape(dat, idvar = "FamilyID", timevar = "timevar", direction = "wide") See ?reshape. Hope this helps, Rui Barradas Em 14-02-2013 21:07, Jamie escreveu: For an analysis of data fro

Re: [R] match a task No. to a few person-IDs

2013-02-15 Thread Rui Barradas
ids, all.x = TRUE) Hope this helps, Rui Barradas Em 15-02-2013 09:45, Mat escreveu: hello together, i have a task No. in a data.frame Task_No Team A49397 1 B49396 1 and now i want to match my Person-IDs to each Task_No. My Person Ids l

Re: [R] sprintf in system command

2013-02-15 Thread Rui Barradas
Hello, In what follows I've used print(), not system(). The trick is to use paste0() to form the command. for (i in 1:10) { cmd <- paste0('C:/Users/.../dssp-2.0.4-win32.exe -i ', sprintf("data_%s.txt",i), ' -o ', sprintf("data_%s.dssp",i

Re: [R] two dimensional integration

2013-02-16 Thread Rui Barradas
Hello, Though I think you should compute that integral symbolically by hand and then define a function with the result, maybe package pracma can do what you want. [functions dblquad(9 and quad2d()] Hope this helps, Rui Barradas Em 16-02-2013 17:01, julia cafnik escreveu: Dear R-users

Re: [R] Extracting Numeric Columns from Data Fram

2013-02-16 Thread Rui Barradas
lps, Rui Barradas Em 16-02-2013 18:15, Barry DeCicco escreveu: Hello, I've got a data frame with a mix of numeric, integer and factor columns. I'd like to pull out (or just operate only on) the numeric/integer columns. Every thing I've found in searches is about how to subset by rows,

Re: [R] Loop

2013-02-17 Thread Rui Barradas
Hope this helps, Rui Barradas Em 17-02-2013 18:53, Trying To learn again escreveu: Hi all, I want to execute a loop of a program: for (u in Timeframemin:Timeframe){} Imagine that Timeframemin<-10 Timefram<-1 Is it posible to execute the loop but only proving from 10 to 1 but jumpi

Re: [R] Calculating seasonal anomalies

2013-02-18 Thread Rui Barradas
Hello, Try the following. Month <- format(Dat$open_date, "%m") anom <- Dat$Dry_w - ave(Dat$Dry_w, Month, FUN = function(x) mean(x, na.rm = TRUE)) st.anom <- Dat$PP_int - ave(Dat$PP_int, Month, FUN = function(x) mean(x, na.rm = TRUE)) Hope this helps, Rui Barradas

Re: [R] continuous shading in plots

2013-02-18 Thread Rui Barradas
Hello, Or with base R only, smooth <- colorRampPalette(c('white', 'darkgrey')) segments(rep(0,100),seq(-4.5,0,length.out=200),rep(14,200), seq(0,4.5,length.out=200), col = smooth(200), lwd = 2) Hope this helps, Rui Barradas Em 18-02-2013 23:30, Jim Lemon escreveu:

Re: [R] creating a new variable.

2013-02-19 Thread Rui Barradas
Hello, Try the following. levels <- c("democrat", "republican", "other") dem <- c(1,1,1,1,0,0,0,0) rep <- c(1,1,1,0,0,0,0,0) other <- c(1,0,0,0,0,0,0,0) party <- factor(rep(levels, c(sum(dem), sum(rep), sum(other party Hope this helps, R

Re: [R] Converting the data in year month day hour and minutes to date

2013-02-19 Thread Rui Barradas
Hello, Try the following. x <- "2008-01-01 02:30" as.POSIXct(x, format = "%Y-%m-%d %H:%M") Hope this helps, Rui Barradas Em 19-02-2013 17:47, Janesh Devkota escreveu: Hi , I am trying to convert the date as factor to date using "as.date" function in R.

Re: [R] make a list with names with s/lapply

2013-02-19 Thread Rui Barradas
Hello, I'm not sure I understabd, but if the names are in 'namen' then the following might do what you want. names(open.list) <- namen Hope this helps, Rui Barradas Em 19-02-2013 18:09, Hermann Norpois escreveu: Hello, I open some files in a directory and get a

Re: [R] type 3 aov for repeated measures

2013-02-20 Thread Rui Barradas
Hello, Try function Anova() in package car. #install.packages("car") library(car) ?Anova # see argument 'type' Hope this helps, Rui Barradas Em 20-02-2013 09:08, Anders Sand escreveu: Hi, I know this question has been asked before but I have not seen an answer pe

Re: [R] Fitting a gaussian distribution to a plot

2013-02-21 Thread Rui Barradas
ll.equal(d1, d2) # TRUE Hope this helps, Rui Barradas Em 21-02-2013 02:55, arun escreveu: Hi, Do you need "exp^"? Should it be "exp(-((...? x1<-as.numeric(x) sd1<-sd(small) mean1<- mean(small) ((1/sd1)*sqrt(2*pi))*exp(-((x1-mean1)^2)/(2*(sd1^2))) # [1] 4.1

Re: [R] (no subject)

2013-02-21 Thread Rui Barradas
Hello, http://lmgtfy.com/?q=sum+columns+in+R The first hit looks promising. Hope this helps, Rui Barradas Em 21-02-2013 07:33, nandita srivastava escreveu: how to sum columns in R? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman

Re: [R] functional median polish

2013-02-21 Thread Rui Barradas
Hello, Try package sos first: library(sos) findFn('functional median') # 'functional median polish' returns nothing Package fda.usc is first. findFn('functional anova') # also gets package fda.usc Hope this helps, Rui Barradas Em 21-02-2013 18:15, f

Re: [R] Merging data in arrays

2013-02-22 Thread Rui Barradas
<- nrow(res[[1]]) m <- ncol(res[[1]]) n <- length(res) array(unlist(res), dim = c(k, m, n)) } G <- fun(C, E) identical(F, G) #TRUE Hope this helps, Rui Barradas Em 22-02-2013 03:40, Ray Cheung escreveu: Thanks, Jeff. Here is a simplified hypothetical sample (sorry

Re: [R] How to merge two functions into one?

2013-02-22 Thread Rui Barradas
ays zero } else { return(NA) } } cor_withN <- function(...) { res <- try(return_cor(...), silent=TRUE) ifelse(class(res)=="try-error", NA, res) } cor_withN(1:10, 1:10 + rnorm(10)) cor_withN(1:2, 1:2 + rnorm(2)) Hope this helps, Rui Barrad

Re: [R] Selecting First Incidence from Longitudinal Data

2013-02-23 Thread Rui Barradas
0 0 1 30 0 1 30 0 1 30 0 1 32 0 1 40 1 2 40 1 2 ", header = TRUE) aggregate(. ~ ID, data = subset(dat, COMPL != 0), head, 1) Hope this helps, Rui Barradas Em 23-02-2013 14:28, Tasnuva Tabassum escr

Re: [R] Fitting this data with a gaussian would be great

2013-02-23 Thread Rui Barradas
Hello, Why do you think your data is gaussian? For what it's worth, qqnorm(small) # doesn't look qqline(small) # gaussian Hope this helps, Rui Barradas Em 22-02-2013 23:27, Samantha Warnes escreveu: Hello,I'm still working with this data set, and trying to fit it with a

Re: [R] data.frame and import to xlsx

2013-02-24 Thread Rui Barradas
o the problem should be solved. Hope this helps, Rui Barradas Em 23-02-2013 22:14, sisi26 escreveu: Hi, i have a very huge number of data with the size 2375ko, i want to import them for R to xlsx but the size of excel is limited How can i resolve this problem? And please how can i define the frame

Re: [R] data.frame and import to xlsx

2013-02-24 Thread Rui Barradas
reated above writeWorksheet(wb, SP, sheet = "SP") # Save workbook - this actually writes the file 'etch1.xlsx' to disk saveWorkbook(wb) Hope this helps, Rui Barradas Em 24-02-2013 17:42, Sihem Ben Zakour escreveu: I have a data, you can read them with this function SP &l

Re: [R] Data frame as table

2013-02-25 Thread Rui Barradas
Hello, If your data.frame is named 'dat', the following might be what you want. as.table(data.matrix(dat)) Hope this helps, Rui Barradas Em 25-02-2013 11:35, franck.berth...@maif.fr escreveu: Hello R user's, I've read a txt file with the read.table syntax. This file

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

2013-02-25 Thread Rui Barradas
y[,1], y[,2], y[,3]), ] Then use the rest of your code. Or, which would save us the sorting, paste the rows elements together directly from matrix 'y' and use the fact that table() sorts its output. w2 <- apply( y , 1 , paste0 , collapse = "" ) table(w2) Hope this

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