similar to: Function question

Displaying 20 results from an estimated 10000 matches similar to: "Function question"

2010 Nov 09
3
Row-wise recurive function call
Dear Group, I have a following dataset: > a A B C D 1 22 3 31 40 2 26 31 36 32 3 3 7 49 16 4 24 40 27 26 5 20 45 47 0 6 34 43 11 18 7 48 48 24 2 8 3 16 39 48 9 20 49 7 21 10 17 36 47 10 > dput(a) structure(list(A = c(22L, 26L, 3L, 24L, 20L, 34L, 48L, 3L, 20L, 17L), B = c(3L, 31L, 7L, 40L, 45L, 43L, 48L, 16L, 49L, 36L), C = c(31L, 36L, 49L, 27L, 47L, 11L, 24L,
2012 Apr 20
3
Matrix multiplication by multple constants
Dear R helpers Suppose x  <- c(1:3) y  <- matrix(1:12, ncol = 3, nrow = 4) > y      [,1] [,2] [,3] [1,]    1    5    9 [2,]    2    6   10 [3,]    3    7   11 [4,]    4    8   12 I wish to multiply 1st column of y by first element of x i.e. 1, 2nd column of y by 2nd element of x i.e. 2 an so on. Thus the resultant matrix should be like > z      [,1]   [,2]    [,3] [1,]    1   
2008 Sep 17
5
Loop on vector name
[My previous message rejected, therefore I am sending same one with some modification] I have 3 vectors with object name : dat1, dat2, dat3 Now I want to create a loop, like : for (i in 1:3) { cat(sd(dati)) } How I can do this in R? Regards,
2009 Feb 17
2
Efficient matrix computations
Hi, I am looking for two ways to speed up my computations: 1. Is there a function that efficiently computes the 'sandwich product' of three matrices, say, ZPZ' 2. Is there a function that efficiently computes the determinant of a positive definite symmetric matrix? Thanks, S.A. [[alternative HTML version deleted]]
2010 Jul 26
2
Concatenate a mix of numbers and letters to create a vector name
Dear all, I am trying to create a vector name, for example tmax.195012 from tmax., 1950 and 12. Obviously I don't wish to simply type it because the 3 name components are changing in each iteration within a loop. Is there any way of concatenating those 3 components (which are a mixture of numbers and letters)? Thanks for reading, Panos
2011 Aug 23
4
Correlation discrepancy
Dear R list, I have one very elementary question regrading correlation between two variables. x = c(44,46,46,47,45,43,45,44) y = c(44,43,41,41,46,48,44,43) > cov(x, y) [1] -2.428571 However, if I try to calculate the covariance using the formula as covariance = sum((x-mean(x))*(y-mean(y)))/8       # no of of paired obs. = 8 or     covariance = sum(x*y)/8-(mean(x)*mean(y)) gives
2012 Mar 06
2
Numerical Inversion of Cumulative Distribution Function
Dear R users, Given a user-defined cumulative distribution function F, I want to compute F^{-1}(x). How is that possible with R? Best Regards, -- Gildas Mazo PhD student MISTIS team at INRIA Grenoble, France [[alternative HTML version deleted]]
2010 Mar 09
3
Removing Zeros from matrix
Hi Everybody, I have a matrix of about 45 columns. Some of the rows contain zeros. Using >data1<-data[complete.cases(data),], I can remove the "NA" rows. But I am unable to tackle that of zeros. Can anybody give me an idea of how to remove rows containing zeros in a matrix. Thanks so much Best Ogbos [[alternative HTML version deleted]]
2008 Oct 14
4
request: How to ignore columns having zero sums
Dear friends I have an array consist of r-rows and c-columns e.g. x=c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,0,0,0,0,0,0,0,0); x1=array(x, dim=c(4,6)) output is > x1 [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 2 3 4 0 0 [2,] 1 2 3 4 0 0 [3,] 1 2 3 4 0 0 [4,] 1 2 3 4 0 0 How can i ignore columns having zero sums? Help in this regard
2010 Sep 06
3
Aggregate certain rows in a matrix
Hi, I have a matrix that looks like this a <- c(1,1,1,1,2,2,3,3,3,3) b <- c(2,2,2,3,4,4,4,5,5,6) c <- c(1,2,3,4,5,6,7,8,9,10) M <- matrix(nr=10,nc=3) M[,1] <- a M[,2] <- b M[,3] <- c > M [,1] [,2] [,3] [1,] 1 2 1 [2,] 1 2 2 [3,] 1 2 3 [4,] 1 3 4 [5,] 2 4 5 [6,] 2 4 6 [7,] 3 4 7
2009 Jun 08
5
mean
Hi, I have gote the following data x1 <- c(rep(1,6),rep(4,7),rep(6,10)) x2 <- rnorm(length(x1),6,1) data <- data.frame(x1,x2) and I would like to compute the mean of the x2 for each individual of x1, i. e. x1=1,4 and 6? Thank you very much in advance, Amori [[alternative HTML version deleted]]
2012 Nov 01
3
convert list without same component length to matrix
Hi, I have this lame question. I want to convert a list (each with varies in length) to matrix with same row length by eliminating vectors outside the needed range. For example: l<-list(NULL) l[[1]]=1,2,3.7 l[[2]]=3,4,5,6,3 l[[3]]=4,2,5,7 l[[4]]=2,4,6,3,2 l[[5]]=3,5,7,2 #so say I want to only have 4 rows and 5 column in my matrix (or data.frame) and eliminating the 5th index value in l[[2]]
2010 Feb 15
2
creating functions question
Hi All, I am interested in creating a function that will take x number of lm objects and automate the comparison of each model (using anova). Here is a simple example (the actual function will involve more than what Im presenting but is irrelevant for the example): # sample data: id<-rep(1:20) n<-c(10,20,13,22,28,12,12,36,19,12,36,75,33,121,37,14,40,16,14,20)
2010 Nov 07
3
regular exprs
Dear All, I would appreciate any help with the following: given the vector 'x' x <- c("Ass1", "Ass.s1", "Ass2", "Ass.s2") I would like to pick up the positions where the character string contains "Ass" but does not contain "Ass.s", so for 'x' that would be positions 1 and 3. I guess this could be programmed around
2009 Feb 12
3
get top 50 correlated item from a correlation matrix for each item
Hi, I have a correlation matrix of about 3000 items, i.e., a 3000*3000 matrix. For each of the 3000 items, I want to get the top 50 items that have the highest correlation with it (excluding itself) and generate a data frame with 3 columns like ("ID", "ID2", "cor"), where ID is those 3000 items each repeat 50 times, and ID2 is the top 50 correlated items with ID,
2010 Oct 15
4
split data with missing data condition
Dear all I have data like this: x y [1,] 59.74889 3.1317081 [2,] 38.77629 1.7102589 [3,] NA 2.2312962 [4,] 32.35268 1.3889621 [5,] 74.01394 1.5361227 [6,] 34.82584 1.1665412 [7,] 42.72262 2.7870875 [8,] 70.54999 3.3917257 [9,] 59.37573 2.6763249 [10,] 68.87422 1.9697770 [11,] 19.00898 2.0584415 [12,] 60.27915 2.5365194 [13,] 50.76850
2008 Dec 11
5
Extracting the name of an object into a character string
Dear List, I am writing a function in R with the facility to store models for later use in scoring. It would be very useful if I could include in the name of the file stored the name of the model object being stored, this name being chosen by the user in the function call. A simple function to store the name of an object as a character string would fit the bill, but I have not found one. name()
2009 Jan 13
5
indexing question
Hi all, i have a pretty easy indexing question, at least i believe so. The main reason i post it here, is that brackets and $ are hard to google. How do I index correctly, if i just want to display the whole dataset conditioned on the fact that some particular column equals one. I know i can do something like: data$somecolumn[data$particularcol ==1] . That will show all "some
2008 Dec 03
3
alternative way to replicate()
Dear all, I'm looking for an alternative way to replicate the "2," string for an x number of times, and end up with one string containing "2," x times. I can partly achieve this using replicate(). > y <- rep("2,", times=3) > y [1] "2," "2," "2," The output that I am looking for is, however, "2,2,2,". I also tried
2009 Aug 10
2
Viewing function code
Hi, in the quest of learning from others' codes, I am still stumbling over the problem how to view some of the functions. I know about methods() & getAnywhere(), showMethods(), getMethods() but I still cannot view every function. How would I look at the code of the "merge" function? Thanks a million, Werner -- View this message in context: