Re: [R] scatter3D and colours

2016-07-14 Thread Jorge I Velez
result you expect. > > Thanks for the complete reproducible example. I wouldn't have even > looked at your problem without something to test. > > Sarah > > On Thu, Jul 14, 2016 at 1:55 PM, Jorge I Velez > wrote: > > Dear R-help, > > > > I am using the

[R] scatter3D and colours

2016-07-14 Thread Jorge I Velez
Dear R-help, I am using the plot3D package to produce 3D spheres along with 95% CIs distinguishing each sphere with a predefined colour (see the reproducible example at the end). I have been successful in producing a similar plot using a different data set (kindly see https://www.dropbox.com/s/sn

Re: [R] Extract every 2 element for a list which are not equal in length

2016-03-07 Thread Jorge I Velez
Dear Mohammad, What's wrong with the result? Best, Jorge.- On Monday, March 7, 2016, Mohammad Tanvir Ahamed via R-help < r-help@r-project.org> wrote: > Hi, > > a <- c(1:5)b <- c(1:3) > c <- 1 > d <- 5 > e <- list(a,b,c,d) > > # To extract every 1st element > lapply(e,"[[",1) > > ## Out-put > [[1]

Re: [R] Extract entries from matrix

2015-11-04 Thread Jorge I Velez
t;- numeric(nrow(m)) > j <- 1 > for (i in 1:nrow(m)) { > if (j > ncol(m) || m[i,j] == 0) { > j <- 1 > } > v[i] <- m[i,j] > j <- j+1 > } > > v > > Note that this puts 0 in the output if > there is a zero in your first column and >

Re: [R] Extract entries from matrix

2015-10-28 Thread Jorge I Velez
. The output vector would then be of the same length as the number of rows in "m", and would contain the elements previously selected. Any ideas on how to proceed? Thank you very much in advance. Best regards, Jorge Velez.- On Tue, Oct 27, 2015 at 4:38 PM, Jorge I Velez wrote: &

Re: [R] Extract entries from matrix

2015-10-27 Thread Jorge I Velez
leave them out, but then we have 4th: 1, 2, 3; 5th: 1, > 2, 3; 6th: 1, 2, 3, 4, etc so you must have some additional rule in mind to > get your answer. > > - > David L Carlson > Department of Anthropology > Texas A&M University > Coll

Re: [R] Extract entries from matrix

2015-10-27 Thread Jorge I Velez
345 > [22,]12345 > > indx > [,1] [,2] > [1,]41 > [2,]52 > [3,]63 > [4,]71 > [5,]82 > [6,]93 > [7,] 101 > [8,] 11 2 > [9,] 123 > > m[indx] >

[R] Extract entries from matrix

2015-10-27 Thread Jorge I Velez
Dear R-help, I am working with a matrix "m" from which I would like to extract some elements. An toy example is as follows: ## input matrix m <- structure(c(0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,

Re: [R] Number of digits to display?

2015-10-26 Thread Jorge I Velez
Dear Judson, Perhaps the following example would give you some ideas: R> options(digits = 4) R> rnorm(5) #[1] -0.57089 -0.14759 0.05717 -0.04935 2.22123 R> options(digits = 3) R> rnorm(5) #[1] 0.789 0.616 0.156 -1.315 -1.090 R> options(digits = 2) R> rnorm(5) #[1] -1.04 -0.58 -0.50 0.30 0.

[R] Update dataframe based on some conditions

2015-10-21 Thread Jorge I Velez
Dear R-help, I am working on what it seems to be a simple problem, but after several hours trying to come up with a solution, unfortunately I have not been able to. I would like to go from "datain" to "dataout", that is, create the NEWREF variable according with some restrictions, and update the

Re: [R] Count number in r

2015-05-19 Thread Jorge I Velez
Dear Arshad, Here is a possibility using tapply(): with(d, tapply(Rain, list(Month, Year), function(x) sum(x > .1))) ##1971 #1 12 #20 where "d" is your data.frame(). See also ?aggregate and ?ave. Best, Jorge.- On Tue, May 19, 2015 at 8:10 PM, Hafizuddin Arshad < hafizuddinarsha...@gm

[R] Help with pedigree() function in kinship2

2015-05-12 Thread Jorge I Velez
Dear R-help, I am interested in plotting some pedigrees and came across the kinship2 package. What follows is an example of the pedigrees I am working with. Now, when running ## check package availability if(!require(kinship2)) install.packages('kinship2') require(kinship2) ## data to plot d <

Re: [R] How to access https page

2015-03-09 Thread Jorge I Velez
Hi Hui, I have used the source_url function in the devtools package with good results. Give it a shot! Best, Jorge.- On Tue, Mar 10, 2015 at 9:39 AM, Hui Du wrote: > Hi All, > > I am trying to parse some information from website, say, a linkedin page. > The linkedin url was > > url = "http:/

Re: [R] Save a plot with a name given as an argument in a function

2015-02-09 Thread Jorge I Velez
Hi Evgenia, Try test2 <- function(data, TitleGraph){ pdf(paste0(TitleGraph, ".pdf"), width = 7, height = 5) plot(data) dev.off() } instead. Take a look at ?paste0 for more information. HTH, Jorge.- On Tue, Feb 10, 2015 at 12:14 AM, Evgenia wrote: > test<-function(data, TitleGraph){ > > > p

[R] Proportion of equal entries in dist()?

2015-01-19 Thread Jorge I Velez
Dear all, Given vectors "x" and "y", I would like to compute the proportion of entries that are equal, that is, mean(x == y). Now, suppose I have the following matrix: n <- 1e2 m <- 1e4 X <- matrix(sample(0:2, m*n, replace = TRUE), ncol = m) I am interested in calculating the above proportion f

Re: [R] non negativity constraints if else function

2014-12-20 Thread Jorge I Velez
What about ifelse(w < 0, 0, w) See ?ifelse for more information. Best, Jorge.- On Sat, Dec 20, 2014 at 3:26 PM, Esra Ulasan wrote: > Hello, > > I have tried the solve the non-negativity constraint "if else function" in > R. But I have done something wrong because it still gives the same > so

Re: [R] keep only the first value of a numeric sequence

2014-12-15 Thread Jorge I Velez
Dear jeff6868, Here is one way: ifelse(with(data, c(0, diff(mydata))) != 1, 0, 1) You could also take a look at ?rle HTH, Jorge.- On Mon, Dec 15, 2014 at 9:33 PM, jeff6868 wrote: > > Hello dear R-helpers, > > I have a small problem in my algorithm. I have sequences of "0" and "1" > values i

Re: [R] Creating a new column from a series of columns

2014-10-31 Thread Jorge I Velez
Dear Dennis, Assuming that your data.frame() is called dd, the following should get you started: colnames(dd[,-1])[apply(dd[,-1], 1, function(x) which(x == 'Yes'))] HTH, Jorge.- On Sat, Nov 1, 2014 at 12:32 PM, Fisher Dennis wrote: > R 3.1.1 > OS X > > Colleagues, > I have a dataset containi

Re: [R] print vectors with consecutive numbers

2014-08-22 Thread Jorge I Velez
Hi James, Try mat[, apply(mat, 2, function(x) any(diff(x) == 1))] HTH, Jorge.- On Fri, Aug 22, 2014 at 10:18 PM, James Wei wrote: > > > Hi all, > > I have a matrix with consecutive and non-consecutive numbers > in columns. For example, the first 2 columns have consecutive numbers. I > want

Re: [R] data.table/ifelse conditional new variable question

2014-08-17 Thread Jorge I Velez
gt; number of items to replace is not a multiple of replacement length > > looking at the output I get numbers where the father/mother ID should > be in the M/PID field. For example: > > 2702 349 mother 0 0 > 2702 3456 sibling 0 842 > 2702 9980 sibling

Re: [R] data.table/ifelse conditional new variable question

2014-08-17 Thread Jorge I Velez
ing error: > > > > Error in l$PID[l$\Relationship == "sibling"] <- l$Sample.ID[father] : > > replacement has length zero > > > > > > > > On Sat, Aug 16, 2014 at 6:48 PM, Jorge I Velez > wrote: > >> Dear Kate, > >> > &

Re: [R] data.table/ifelse conditional new variable question

2014-08-16 Thread Jorge I Velez
Dear Kate, Assuming you have nuclear families, one option would be: x <- read.table(textConnection("Family.ID Sample.ID Relationship 14 62 sibling 14 94 father 14 63 sibling 14 59 mother 17 6004 father 17 6003 mother 17 6005 s

Re: [R] reshape a dataset

2014-08-15 Thread Jorge I Velez
nal output is a list. > How do I covert it back a dataframe? > -Sohail > > > On Fri, Aug 15, 2014 at 5:37 AM, Jorge I Velez > wrote: > >> Dear Sohail, >> >> Using Jim's data set skdat, two more options would be >> >> # first option >

Re: [R] reshape a dataset

2014-08-15 Thread Jorge I Velez
Dear Sohail, Using Jim's data set skdat, two more options would be # first option d <- with(skdat, table(ID, lettertag)) names <- colnames(d) d <- c(list(rownames(d)), lapply(1:ncol(d), function(i) as.numeric(d[,i]))) names(d) <- c('ID', names) d # second option d <- with(skdat, table(ID, letter

Re: [R] Possible pair of 2 binary vectors

2014-08-09 Thread Jorge I Velez
Dear Ron, What about this? set.seed(123) d <- 4 x1 <- sample(0:1, d, TRUE) x2 <- sample(0:1, d, TRUE) x1 x2 expand.grid(x1 = x1, x2 = x2) See ?expand.grid for more information. Best, Jorge.- On Sat, Aug 9, 2014 at 7:46 PM, Ron Michael wrote: > Hi, > > Let say I have 2 binary vectors of len

Re: [R] Grouped Boxplot

2014-07-11 Thread Jorge I Velez
Dear Anupam, Try boxplot(DISO ~ POS * NODE_CAT, data = yourdata) Another option would be the last example in ?boxplot HTH, Jorge.- On Fri, Jul 11, 2014 at 4:38 PM, anupam sinha wrote: > Dear all, > I need some help with plotting boxplots in groups. I have a > file of the followin

Re: [R] From long to wide format

2014-06-30 Thread Jorge I Velez
}, mc.cores = 4) > X[, -1] <- do.call(rbind, r) > X > }) > > # user system elapsed > # 0.125 0.011 0.074 > > > wide2 <- wide1 > wide2$id <- as.character(wide2$id) > wide$id <- as.character(wide$id) > all.equal(wide, wide2,

[R] From long to wide format

2014-06-29 Thread Jorge I Velez
Dear R-help, I am working with some data stored as "filename.txt.gz" in my working directory. After reading the data in using read.table(), I can see that each of them has four columns (variable, id, outcome, and rate) and the following structure: # sample data x2 <- data.frame(variable = rep(pas

Re: [R] counting the number of rows that satisfy a certain criteria

2014-06-21 Thread Jorge I Velez
Hi Kate, You could try sum(X[, 1] == 1 & X[, 2] == 1) where X is your data set. HTH, Jorge.- On Sun, Jun 22, 2014 at 12:57 AM, Kate Ignatius wrote: > I have 4 columns, and about 300K plus rows with 0s and 1s. > > I'm trying to count how many rows satisfy a certain criteria... for > instan

Re: [R] barp {plotrix} Start bars at 0 with a vector of positive values

2014-06-13 Thread Jorge I Velez
Hi Pascal, Perhaps I am missing something, but what about changing passing ylim = c(0, 10) to barp()? Best, Jorge.- On Fri, Jun 13, 2014 at 7:50 PM, Pascal Oettli wrote: > Dear list, > > Please consider the following example: > > library(plotrix) > barp(c(2,3,4,5,6,7,8), ylim=c(-10,10)) > > H

Re: [R] How to print something in the same location in console?

2014-06-12 Thread Jorge I Velez
Dear Juan, Perhaps the last example in http://stat.ethz.ch/R-manual/R-devel/library/utils/html/txtProgressBar.html is what you are looking for. Best, Jorge.- On Thu, Jun 12, 2014 at 8:49 PM, Juan Andres Hernandez < jhernandezcabr...@gmail.com> wrote: > Hi I need to print the iteration number o

Re: [R] Problem with rbind.fill

2014-06-01 Thread Jorge I Velez
Hi Bill, You need require(plyr) ?rbind.fill and then the rest of the code you already tried. Best, Jorge.- On Mon, Jun 2, 2014 at 3:49 AM, Bill Bentley wrote: > The following works as it should... > > > both<-rbind(females,males) > > > both > > workshop gender q1 q2 q3 q4 > > 11

Re: [R] Problem with products in R ?

2014-05-04 Thread Jorge I Velez
Try options(digits = 22) 168988580159 * 36662978 # [1] 6195624596620653568 HTH, Jorge.- On Sun, May 4, 2014 at 10:44 PM, ARTENTOR Diego Tentor < diegotento...@gmail.com> wrote: > Trying algorithm for products with large numbers i encountered a difference > between result of 168988580159 * 366

Re: [R] Return "TRUE" only for first match of values between matrix and vector.

2014-05-02 Thread Jorge I Velez
Hi Nevil, Try apply(A, 2, function(x) x == B) HTH, Jorge.- On Fri, May 2, 2014 at 6:46 PM, nevil amos wrote: > I wish to return " True" in a matrix for only the first match of a value > per row where the value equals that in a vector with the same number of > values as rosw in the matrix >

Re: [R] how to extract a part of objects from list ?

2014-05-01 Thread Jorge I Velez
Hi Kristi, Try out1970$smoot HTH, Jorge.- On Fri, May 2, 2014 at 10:00 AM, Kristi Glover wrote: > Hi R User, > I am wonedring how I can extract a part of objects from list. > > For example > > > str(out1970) > List of 8 > $ comm : num [1:16, 1:57] 1 1 1 1 1 1 1 1 1 1 ... > ..- attr(*,

Re: [R] Faster way to transform vector [3 8 4 6 1 5] to [2 6 3 5 1 4]

2014-04-26 Thread Jorge I Velez
Hi Xueming, Try (1:length(bo))[rank(bo)] In a function the above would be f <- function(x){ N <- length(x) (1:N)[rank(x)] } f(bo) # [1] 2 6 3 5 1 4 HTH, Jorge.- On Sat, Apr 26, 2014 at 7:54 PM, xmliu1...@gmail.com wrote: > Hi, > > could anybody help me to find a fast way to fi

Re: [R] for loop to list files

2014-04-21 Thread Jorge I Velez
Hi Beatriz, Try paste("val_mapped_petpe_", 1976:1981, "01.txt", sep="") Best, Jorge.- On Mon, Apr 21, 2014 at 6:43 PM, Beatriz R. Gonzalez Dominguez < aguitatie...@hotmail.com> wrote: > Dear all, > > I'm trying to create a loop to select a series of files into my computer > but I haven't been

Re: [R] Selecting numbers not divisible by 3

2014-03-27 Thread Jorge I Velez
Hi there, Try X[X %% 3 == 0] HTH, Jorge.- On Thu, Mar 27, 2014 at 6:46 PM, Prabhakar Ghorpade < dr.prabhaka...@gmail.com> wrote: > Hi, > here's my code > > X <- 1:100 > > I want to select number divisible by 3 out of them how can I select it? > > ( I tried following > X <- 1:100 > DIV <- Y -

Re: [R] Calculations with aggregate data: confidence intervals

2014-03-25 Thread Jorge I Velez
Hi Luigi, Thanks for sending the data in reproducible format. Perhaps something like this? aggregate(my.data[,3], list(my.data[,2]), FUN = function(x) t.test(x)$ conf.int[1:2]) #Group.1 x.1 x.2 #1 Unstimulated 5.296492e+02 2.410510e+03 #2ESAT6 9.105338e+00 4.078

Re: [R] plotting vectors of different lengths

2014-03-22 Thread Jorge I Velez
You are welcome, Eliza. If I understand correctly, the following will do: x <- 1:8 y <- 1:5 matrix(apply(expand.grid(x = y, y = x), 1, function(r) paste0("(", r[1], ",", r[2], ")")), ncol = length(x)) Best, Jorge.- On Sat, Mar 22, 2014 at 10:37 PM, eliza botto wrote: > Thankyou very much jorg

Re: [R] plotting vectors of different lengths

2014-03-22 Thread Jorge I Velez
Hi Eliza, Perhaps the following? matpoints(t(dat), type = 'l') HTH, Jorge.- On Sat, Mar 22, 2014 at 10:18 PM, eliza botto wrote: > > Dear useRs, > I have two column vectors of different lengths say x=1,2,3,4,5,6,7,8 and > y=1,2,3,4,5. I wanted to plot them by using "points()" command over an

Re: [R] replace duplicates with 0

2014-03-13 Thread Jorge I Velez
Hi Catalin, The following should give you some ideas: set.seed(123) x <- rpois(50, 2) x idx <- duplicated(x) x[idx] <- 0 x Best, Jorge.- On Thu, Mar 13, 2014 at 11:35 PM, catalin roibu wrote: > Dear all! > > Is there a possibility to replace all duplicates values in data frame with > 0? > >

Re: [R] dim vector or data.frame

2014-02-14 Thread Jorge I Velez
Hi Berry, What about using NROW(input) ? Best, Jorge.- On Sat, Feb 15, 2014 at 2:26 AM, Berry Boessenkool < berryboessenk...@hotmail.com> wrote: > Hi, > > In my function, I want to allow input to be a vector or a data.frame. > Certain operations need to be done if the length or nrows exceeds

Re: [R] impossible to install package

2014-02-12 Thread Jorge I Velez
Dear Eve, See http://cran.r-project.org/web/packages/languageR/index.html The name of the package is "languageR", not "LanguageR". Best, Jorge.- On Thu, Feb 13, 2014 at 3:39 PM, Eve Dupierrix wrote: > Hi, > I want to install "languageR" but is doesn't work. > > I tried it by two ways: > (1) b

Re: [R] Label point with (x,hat(y))

2013-11-23 Thread Jorge I Velez
Try R> plot(1:10) R> text(1,3, expression("(x, "*hat(y)*")"), pos=3) Best, Jorge.- On Sun, Nov 24, 2013 at 10:51 AM, David Arnold wrote: > Hi, > > I'd like to do this: > > text(1,3,"(x,yhat)",pos=3) > > But using (x,hat(y)). Any suggestions? > > D. > > > > -- > View this message in context: >

Re: [R] left transpose

2013-10-21 Thread Jorge I Velez
Dear Dr. Vokey, Here is one approach, although may not be the more efficient: x <- matrix(1:8, ncol = 4) x # [,1] [,2] [,3] [,4] #[1,]1357 #[2,]2468 t(x[, ncol(x):1]) # [,1] [,2] #[1,]78 #[2,]56 #[3,]34 #[4,]12 leftTranspos

Re: [R] replace Na values with the mean of the column which contains them

2013-07-29 Thread Jorge I Velez
Consider the following: f <- function(x){ m <- mean(x, na.rm = TRUE) x[is.na(x)] <- m x } apply(de, 2, f) HTH, Jorge.- On Tue, Jul 30, 2013 at 2:39 AM, iza.ch1 wrote: > Hi everyone > > I have a problem with replacing the NA values with the mean of the column > which contains them. If I repla

Re: [R] find closest value in a vector based on another vector values

2013-06-18 Thread Jorge I Velez
ues you choose to be different or not, in which case they may not > be minimum? > > a <- c(1, 8, 9) > b <- c(2,3) > > Then what are the 2 closest values of a to b? > > -- Bert > > On Tue, Jun 18, 2013 at 5:43 AM, Jorge I Velez > wrote: > > Dear Andras

Re: [R] find closest value in a vector based on another vector values

2013-06-18 Thread Jorge I Velez
Dear Andras, Try > a[findInterval(b, a)] [1] 8 32 HTH, Jorge.- On Tue, Jun 18, 2013 at 10:34 PM, Andras Farkas wrote: > Dear All, > > would you please provide your thoughts on the following: > let us say I have: > > a <-c(1,5,8,15,32,69) > b <-c(8.5,33) > > and I would like to extract from

Re: [R] How can we access an element in a structure

2013-06-10 Thread Jorge I Velez
Hi Miao, Try attributes(test1)[[1]] HTH, Jorge.- On Tue, Jun 11, 2013 at 3:49 PM, jpm miao wrote: > Hi, > > I have a structure, which is the result of a function > How can I access the elements in the gradient? > > > dput(test1) > structure(-1.17782911684913, gradient = structure(c(-0.0

Re: [R] boot, what am I doing wrong?

2013-06-07 Thread Jorge I Velez
Hi there, You need a function for your statistic: > boot(x, function(x, index) mean(x[index]), R = 1000) ORDINARY NONPARAMETRIC BOOTSTRAP Call: boot(data = x, statistic = function(x, index) mean(x[index]), R = 1000) Bootstrap Statistics : original biasstd. error t1* 0.40696

Re: [R] Subsetting out missing values for a certain variable

2013-06-05 Thread Jorge I Velez
Daniel, You need "==" instead of "=". HTH, Jorge.- Sent from my phone. Please excuse my brevity and misspelling. On Jun 6, 2013, at 10:36 AM, Daniel Tucker wrote: > Also tried this but results werent any different > > subset1<- subset(dframe, glb_ind="Y" | sample==1 | !is.na(glb_ind)) > subset2

Re: [R] Refer to Data Frame Name Inside a List

2013-06-04 Thread Jorge I Velez
Try names(ResList) HTH, Jorge.- Sent from my phone. Please excuse my brevity and misspelling. On Jun 5, 2013, at 12:34 AM, "Sparks, John James" wrote: > Dear R Helpers, > > I have a fairly complicated list of data frames. To give you an idea of > the structure, the top of the str output is s

Re: [R] Repeating sequence elements

2013-05-17 Thread Jorge I Velez
Try rep(1:length(v), v) HTH, Jorge.- On Fri, May 17, 2013 at 8:53 PM, Stefan Petersson wrote: > I want to create a sequence, repeating each element according to a vector. > > I have this: > > v <- c(4, 4, 4, 3, 3, 2) > > And want to create this: > > 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 5 5 5 6 6 >

Re: [R] How can I find negative items from a vector with a short command?

2013-05-08 Thread Jorge I Velez
[f<0] > [1] -2 -8 -32 -128 > > f[f>0] > [1] 4 16 64 > > f[f=4] > [1] 16 > > > 2013/5/8 Jorge I Velez > >> f [ f < 0 ] >> >> >> On Wed, May 8, 2013 at 11:54 AM, jpm miao wrote: >> >>> Hi, >>> >&g

Re: [R] How can I find negative items from a vector with a short command?

2013-05-07 Thread Jorge I Velez
f [ f < 0 ] On Wed, May 8, 2013 at 11:54 AM, jpm miao wrote: > Hi, > >I have a vector f with some negative columns. I remember that there is > an easy expression that can find out negative items. Can someone tell me > how I can do it? > >It seems to be >f[i such that f[i]<0 ...] > >

Re: [R] How can I access the rowname of a data?

2013-05-06 Thread Jorge I Velez
rownames(a) perhaps? HTH, Jorge.- On Mon, May 6, 2013 at 6:03 PM, jpm miao wrote: > Hi, > >Below is the output from an R package. The first column (4, 5, 6, 7, > which is unnamed) is the company name (code), while the second column > efficiency is the performance of each company, which is

Re: [R] R does not subset

2013-05-03 Thread Jorge I Velez
Hi Kasia, You need subset(REC2, INFECTION=="Infected ") (note the space after "Infected"). HTH, Jorge.- On Fri, May 3, 2013 at 7:48 PM, Katarzyna Kulma wrote: > Hi everyone, > > I know there have been several requests regarding subsetting before, but > none of them really helps with my prob

Re: [R] Need help on matrix calculation

2013-04-29 Thread Jorge I Velez
Sorry, the first line should have been Mat[match( Subscript_Vec, rownames(Mat)),] and the rest remains the same. Best, Jorge.- On Mon, Apr 29, 2013 at 11:45 PM, Jorge I Velez wrote: > Christofer, > > The following should get you started: > > r <- Mat[match(rownames(M

Re: [R] Need help on matrix calculation

2013-04-29 Thread Jorge I Velez
Christofer, The following should get you started: r <- Mat[match(rownames(Mat), Subscript_Vec),] rownames(r) <- Subscript_Vec r HTH, Jorge.- On Mon, Apr 29, 2013 at 11:38 PM, Christofer Bogaso < bogaso.christo...@gmail.com> wrote: > Hello again, > > Let say I have 1 matrix: > > Mat <- matrix

Re: [R] Decomposing a List

2013-04-25 Thread Jorge I Velez
Dear Dr. Harding, Try sapply(L, "[", 1) sapply(L, "[", 2) HTH, Jorge.- On Thu, Apr 25, 2013 at 8:16 PM, Ted Harding wrote: > Greetings! > For some reason I am not managing to work out how to do this > (in principle) simple task! > > As a result of applying strsplit() to a vector of character

Re: [R] Looking for a better code for my problem.

2013-04-24 Thread Jorge I Velez
Try subset(Dat, AA == "A" | (AA == "B" & BB == "b")) HTH, Jorge.- On Wed, Apr 24, 2013 at 8:21 PM, Christofer Bogaso < bogaso.christo...@gmail.com> wrote: > Hello again, > > Let say I have following data: > > Dat <- structure(list(AA = structure(c(3L, 1L, 2L, 1L, 2L, 3L, 3L, 2L, > 3L, 1L, 1L,

Re: [R] subset dataframe

2013-04-22 Thread Jorge I Velez
Mike, You need subset(agoa, agoa$X.1 == "AGOA ") instead of subset(agoa, agoa$X.1 == "AGOA") (note the space after the last A in "AGOA". HTH, Jorge.- On Tue, Apr 23, 2013 at 7:14 AM, Mihai Nica wrote: > I can't understand what is happening. This is the code and results: > > > agoa <- read

Re: [R] Subsetting a large number into smaller numbers and find the largest product

2013-04-18 Thread Jorge I Velez
Dear Janesh, Here is one way: # note "x" is a character x <- "73167176531330624919225119674426574742355349194934969835203127745063262395783180169848018694788518438586156078911294949545950173795833195285320880551112540698747158523863050715693290963295227443043557" k <- nchar(x) # digits in x b <

Re: [R] Error: could not find function "invlogit" and "bayesglm"

2013-04-17 Thread Jorge I Velez
Hi Carrington, You also need the boot package (see http://stat.ethz.ch/R-manual/R-patched/library/boot/html/inv.logit.html ) As for the other function, please load the arm package, e.g., require(arm) require(boot) and then you will be able to use the functions mentioned below. HTH, Jorge.- O

Re: [R] non linear equation

2013-04-10 Thread Jorge I Velez
equation, but the problem >> in nls is to anticipate the regression coefficients. >> >> >> On 10 April 2013 12:19, Jorge I Velez wrote: >> >>> Dear Catalin, >>> >>> You can look at ?nls. >>> >>> Alternatively, you could also

Re: [R] non linear equation

2013-04-10 Thread Jorge I Velez
Dear Catalin, You can look at ?nls. Alternatively, you could also consider a linear model as follows, where "d" is your data: # plot your data with(d, plot(cls, proc, las = 1)) # linear model fit <- lm(proc ~ I(1/cls) + I((1/cls)^2), data = d) summary(fit) # plotting with(d, plot(cls, proc, la

Re: [R] Generating a bivariate joint t distribution in R

2013-04-02 Thread Jorge I Velez
Dear Miao, Check require(MASS) ?mvrnorm for some ideas. HTH, Jorge.- On Wed, Apr 3, 2013 at 4:57 PM, jpm miao <> wrote: > Hi, > >I conduct a panel data estimation and obtain estimators for two of the > coefficients beta1 and beta2. R tells me the mean and covariance of the > distribution

Re: [R] 95% Confidence Interval for a p-p plot

2013-04-01 Thread Jorge I Velez
Pablo, Check the qqPlot function in "car": require(car) qqPlot(x, dist = "gamma", shape = 1.7918012, rate = 0.9458022) Best, Jorge.- On Tue, Apr 2, 2013 at 4:41 AM, pablo.castano <> wrote: > Hi, > > I want to create upper and lower 95% confidence intervals for a p-p plot of > an empirical di

Re: [R] Faster way of summing values up based on expand.grid

2013-03-25 Thread Jorge I Velez
Hi Dimitri, If I understood correctly, the following will do: system.time(sum1 <- apply(mycombos, 1, function(x) sum(values1[x]))) system.time(sum2 <- apply(mycombos, 1, function(x) sum(values2[x]))) system.time(sum3 <- apply(mycombos, 1, function(x) sum(values3[x]))) cbind(sum1, sum2, sum3) HTH

Re: [R] trouble with data frame

2013-03-22 Thread Jorge I Velez
Sahana, The notation df[a,b)] is plain wrong. I think you meant (but I may be mistaken) df[a, b] and I am not still sure if that would work in your example. Have you instead considered subset()? E.g., subset(df, a <= 10 & b <= 10) See ?subset for more details. Also, "df" is a very bad n

Re: [R] Help on indicator variables

2013-03-21 Thread Jorge I Velez
Try ifelse(ABS ==1 | DEFF == 1, 1, 0) HTH, Jorge.- On Fri, Mar 22, 2013 at 12:02 AM, Tasnuva Tabassum wrote: > I have two indicator variables ABS and DEFF. I want to create another > indicator variable which will take value 1 if either ABS=1 or DEFF=1. > Otherwise, it will take value 0. How c

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

2013-03-21 Thread Jorge I Velez
Or simply subset(dat, a > 0) HTH, Jorge.- On Thu, Mar 21, 2013 at 6:58 PM, Michael Weylandt <> wrote: > > > On Mar 21, 2013, at 7:39, Pierrick Bruneau wrote: > > > Hi Borja, > > > > You may issue: > > > > attach(data) > > No -- bad idea -- dangerous -- confusing statefulness, etc. (See > expl

Re: [R] Counting confidence intervals

2013-03-18 Thread Jorge I Velez
If you don't use apply() it would be even faster: > system.time(sum(mat2[,1] < 12 & mat2[,2] > 12)) user system elapsed 0.004 0.000 0.003 Regards, Jorge.- On Tue, Mar 19, 2013 at 1:21 AM, arun <> wrote: > Hi, > Jorge's method will be faster. > #system.time(res1<-sum(apply(mat2,1,func

Re: [R] Counting confidence intervals

2013-03-18 Thread Jorge I Velez
Thats cumbersome, Arun. > sum(mat1[,1] < 12 & mat1[,2] > 12) [1] 17 will do the job and even faster: > system.time(replicate(1, sum(mat1[,1] < 12 & mat1[,2] > 12))) # user system elapsed # 0.067 0.001 0.078 HTH, Jorge.- On Tue, Mar 19, 2013 at 1:06 AM, arun <> wrote: > Hi, > Try

Re: [R] Counting confidence intervals

2013-03-18 Thread Jorge I Velez
Hi Jim, Try either of the following (untested): sum( x[1, ] < 12 & x[2, ] > 12) sum(apply(x, 2, function(x) x[1] < 12 & x[2] > 12)) where "x" is your 2x1000 matrix. HTH, Jorge.- On Tue, Mar 19, 2013 at 12:03 AM, Jim Silverton <> wrote: > Hi, > I have a 2 x 1 matrix of confidence interva

Re: [R] Extract letters from a column

2013-03-13 Thread Jorge I Velez
AM, SH wrote: > What I want to do is to extrac three letters from first and last name > and to combine them to make another column 'abb'. The column 'abb' is > to be a my final product. I can make column 'abb' using 'paste' > function once I ha

Re: [R] Extract letters from a column

2013-03-13 Thread Jorge I Velez
; Cr" "ad " "old" > > I would like to have letters from first and second elements if possible. > > Thanks for replying, > > Steve > > > On Wed, Mar 13, 2013 at 10:10 AM, Jorge I Velez > wrote: > > Dear SH, > > > > Hmmm... what

Re: [R] Extract letters from a column

2013-03-13 Thread Jorge I Velez
Dear SH, Hmmm... what about substr(tempdf$name, 4, 6)) ? HTH, Jorge.- On Thu, Mar 14, 2013 at 1:06 AM, SH wrote: > Dear list: > > I would like to extract three letters from first and second elements > in one column and make a new column. > > For example below, > > > tempdf = read.table("cli

Re: [R] merge datas

2013-03-13 Thread Jorge I Velez
Dear Catalun, If I understood your description, please see ?"%in%" and try subset(x, names(x) %in% c(1834,1876,1901,1928,2006) ) where "x" is your data. HTH, Jorge.- On Wed, Mar 13, 2013 at 9:25 PM, catalin roibu <> wrote: > Hello all! > I have a problem with R. I try to merge data like this

Re: [R] string split at xth position

2013-03-13 Thread Jorge I Velez
Dear Johannes, May not be the best way, but this looks like what you described: > x <- c("a1b1","a2b2","a1b2") > x [1] "a1b1" "a2b2" "a1b2" > substr(x, 1, 2) [1] "a1" "a2" "a1" > substr(x, 3, 4) [1] "b1" "b2" "b2" HTH, Jorge.- On Wed, Mar 13, 2013 at 7:37 PM, Johannes Radinger <> wrote: > Hi,

Re: [R] take two columns from a set of lists

2013-03-11 Thread Jorge I Velez
Is the following that you are looking for? unlist(lapply(x.list, "[", 2)) HTH, Jorge.- On Mon, Mar 11, 2013 at 9:52 PM, ishi soichi <> wrote: > say I have a matrix and lists like > > x <- matrix(c(12.1, 3.44, 0.1, 3, 12, 33.1, 1.1, 23), nrow=2) > > x.list <- lapply(seq_len(nrow(x)), function(i

Re: [R] transpose lists

2013-03-08 Thread Jorge I Velez
One option would be x <- list(c(12.1, 0.1, 12, 1.1), c(3.44, 3, 33.1, 23)) do.call(c, apply(do.call(rbind, x), 2, list)) HTH, Jorge.- On Fri, Mar 8, 2013 at 9:06 PM, ishi soichi wrote: > Thanks. The result should be a list of lists like... > > > x > [[1]] > [1] 12.10 3.44 > > [[2]] > [1] 0.

Re: [R] reduce the size of list

2013-03-07 Thread Jorge I Velez
If I understood correctly, lapply(x, "[", 1:3) will do what you want. HTH, Jorge.- On Fri, Mar 8, 2013 at 5:05 PM, ishi soichi <> wrote: > hi. I have a list like > > x <- list(1:10,11:20,21:30) > > It's a sort of a 3 x 10 matrix in list form. > I would like to reduce the dimension of this lis

Re: [R] How to export data with defined decimal places

2013-03-07 Thread Jorge I Velez
Dear Marin, May be not the cleanest way to do it, but the following seems to work: write.table(as.character(round(pi, 10)), "pi.txt", row.names = FALSE, col.names = FALSE, quote = FALSE) Best, Jorge.- On Fri, Mar 8, 2013 at 11:24 AM, Marino David wrote: > Hi Bert, > > I read both options and

Re: [R] How to reference to the `stats` package in academical paper

2013-03-05 Thread Jorge I Velez
Dear Julien, Check citation('stats') HTH, Jorge.- On Wed, Mar 6, 2013 at 12:05 AM, Julien Mvdb wrote: > The question is in the title. > Then, I would like to know how I should refer to the documentation > regarding the use of each functions. > > Thanks, > > Julien Mehl Vettori > > [

Re: [R] recode data according to quantile breaks

2013-02-19 Thread Jorge I Velez
Hi Alain, The following should get you started: apply(df[,-1], 2, function(x) cut(x, breaks = quantile(x), include.lowest = TRUE, labels = 1:4)) Check ?cut and ?apply for more information. HTH, Jorge.- On Tue, Feb 19, 2013 at 9:01 PM, D. Alain <> wrote: > Dear R-List, > > I would like to re

Re: [R] Correlation with p value

2013-02-13 Thread Jorge I Velez
Nico, Check https://stat.ethz.ch/pipermail/r-help/2008-May/161725.html for some alternatives. You might have to change the structure of your data, though. HTH, Jorge.- On Wed, Feb 13, 2013 at 10:13 PM, Nico Met <> wrote: > Dear all, > > I have a data (bellow) and I want to make a correlation

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Jorge I Velez
Robert, Try match(x, y) HTH, Jorge.- On Tue, Feb 12, 2013 at 9:09 PM, Robert Latest wrote: > Hello all, > > given two vectors X and Y I'd like to receive a vector Z which > contains, for each element of X, the index of the corresponding > element in Y (or NA if that element isn't in Y). > >

Re: [R] Transform every integer to 1 or 0

2013-02-05 Thread Jorge I Velez
Dear Wim, You could try 1*(df > 0) HTH, Jorge.- On Tue, Feb 5, 2013 at 5:33 AM, Wim Kreinen <> wrote: > Hello, > > I have a dataframe with positive integers and > for every value > 0 > I would like to have 1 and the rest should be zero. > > For instance > > 1 0 1 > 0 1 1 > > with df as refere

Re: [R] Transforming 4x3 data frame into 2 column df in R

2013-02-01 Thread Jorge I Velez
Dear Gundala, Try as.data.frame.table(foo) HTH, Jorge.- On Fri, Feb 1, 2013 at 5:00 PM, Gundala Viswanath <> wrote: > I have the following data frame: > > > foo >w x y z > n 1.51550092 1.4337572 1.2791624 1.1771230 > q 0.09977303 0.8173761 1.6123402 0.15107

Re: [R] recoding variables again :(

2013-01-30 Thread Jorge I Velez
Hi David, Check ?"%in%" for a simpler approach. Regards, Jorge.- On Wed, Jan 30, 2013 at 8:42 PM, David Studer <> wrote: > Hello everybody! > > I have again a rather simple question concerning recoding of variables: > > I have a variable/data-frame column BIRTHPLACE containing abbreviations

Re: [R] substring from behind

2013-01-30 Thread Jorge I Velez
Hi Mat, The following should get you started: > s <- "Mercedes_02352" > substr(s, nchar(s) - 3, nchar(s) - 1) [1] "235" > > # defining a function > foo <- function(x, a = 3, b = 1) substr(s, nchar(x) - a, nchar(x) - b) > foo(s) [1] "235" HTH, Jorge.- On Wed, Jan 30, 2013 at 8:05 PM, Mat <> wr

Re: [R] an apply question

2013-01-18 Thread Jorge I Velez
Hi m p, You can use either apply(fhours, 2, function(x) ifelse(x < 0, x + 24, x) or shours <- fhours shours[shours < 0 ] <- shours[shours < 0 ] + 24 shours HTH, Jorge.- On Sat, Jan 19, 2013 at 4:17 PM, m p <> wrote: > Hello, > It should be easu but I cannot figure out how to use apply func

Re: [R] Determining sample size from power function

2013-01-09 Thread Jorge I Velez
Dear Kaveh, Take a look at http://www.statmethods.net/stats/power.html HTH, Jorge.- On Thu, Jan 10, 2013 at 3:21 PM, Kaveh Zakeri <> wrote: > Hello, > > I am trying to get the power function to report the sample size rather > than the power. My goal is to input a variety of values for theta an

Re: [R] how to count "A", "C", "T", "G" in each row in a big data.frame?

2013-01-09 Thread Jorge I Velez
Here is one option (not the best, but does the job): foo <- function(x) table(factor(unlist(strsplit(as.character(x), "")), levels = c('A','C','G','T'))) t(apply(d[, -c(1:4)], 1, foo)) What's wrong with Jim Holtman's solution? HTH, Jorge.- On Thu, Jan 10, 2013 at 3:46 PM, Yao He <> wrote: > H

Re: [R] non-consing count

2013-01-04 Thread Jorge I Velez
Hi Ista, I was doing about something similar when I saw your post, so I took your code and did some timings: > system.time(replicate(100, count.0 <- length(which(x == 0 user system elapsed 5.590 0.173 5.834 > system.time(replicate(100, count.1 <- sum(x == 0))) user syste

Re: [R] Working with Matrix

2013-01-04 Thread Jorge I Velez
> } > FUN(x, y) > } > > fun(Mat1, Mat2) > fun(Mat1, Mat2, `*`) # Note the back quotes > > > Hope this helps, > > Rui Barradas > Em 04-01-2013 12:06, Jorge I Velez escreveu: > >> Dear Christofer, >> >> You can try the following: >> >&g

Re: [R] Working with Matrix

2013-01-04 Thread Jorge I Velez
Dear Christofer, You can try the following: # proccess the matrices foo <- function(m1, m2){ if(ncol(m1) != ncol(m2)) stop('number of columns should be equal') if(nrow(m1) < nrow(m2)){ nas <- matrix(NA, ncol = ncol(m1), nrow = nrow(m2) - nrow(m1)) m1 <- rbind(m1, nas) } else{ nas <- matrix(NA

Re: [R] a question about the computation of expression

2013-01-04 Thread Jorge I Velez
Dear meng, Check I understood correctly, the Ryacas package might do what you want. Check its vignette at http://cran.r-project.org/web/packages/Ryacas/vignettes/Ryacas.pdf Best, Jorge.- On Fri, Jan 4, 2013 at 5:59 PM, meng <> wrote: > Hi all: > I have a question about the computation of expr

  1   2   3   >