similar to: Length of vector without NA's

Displaying 20 results from an estimated 30000 matches similar to: "Length of vector without NA's"

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]]
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,
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
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   
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 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]]
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()
2010 Aug 04
4
Adding collumn to existing data frame
Hi experts, I am trying to write a very flexible method that allows me to add a new column to an existing data frame. This is what I have so far: add.column <- function(df, new.col, name) { n.row <- dim(df)[1] length(new.col) <- n.row names(new.col) <- name return(cbind(df, new.col)) } df <- NULL df <- data.frame(a=c(1,2,3)) df # corect: added NA to new collumn df <-
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
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
2009 Jul 13
4
Combine two matricies
Hi, I have two matricies a and x: a<-matrix(c(3,4,5,2,3,4,1,1,2), nrow=3, ncol=3) [,1] [,2] [,3] [1,] 3 2 1 [2,] 4 3 1 [3,] 5 4 2 x<-matrix(c(3, NA, NA, NA, 2, 5, NA, 2, 2), nrow=3, ncol=3) [,1] [,2] [,3] [1,] 3 NA NA [2,] NA 2 2 [3,] NA 5 2 I wish to combine these two into one matrix using the values from x where x has values, and
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]]
2011 Nov 02
1
Generate a sequence of vectors of different length
Hi everyone After the following setup sector=2 # Define Number of Sectors sectors=LETTERS[seq( from = 1, to = sector )] # Name sectors No_ent=round(3/runif(sector)) # Number of entities per sector #Tot_No_ent=sum(No_ent) Goal is to get a List like (A1, A2, A3, B1, B2, B3, B4) where A is denoting an industrial sector and then a numbered sequence of companies within the sector. The step
2010 Nov 25
1
Applying function to elements of matrices in a list
Hello R-help, Please cc me on all responses, as I only receive summary emails from this list. I'm wondering if anybody has any tips on how to accomplish this efficiently. I have a list of matrices, and I'm trying to get the mean of the [i,j]'th element of each matrix in a list. So if I have a list of matrices, say x <-
2009 Nov 05
2
sort of cumulative counting in a vector
Dear list, I need help, since I can not come up with an easy solution to convert this vector test <- c('p','p','t','t','t') to [1] NA NA 1 2 3 which means the occurences of 't' should be summed up at the corresponding positions. The solution should also be able to handle the following scenarios: test2 <-
2009 Mar 07
2
Recode factor into binary factor-level vars
How to I "recode" a factor into a binary data frame according to the factor levels: ### example:start set.seed(20) l <- sample(rep.int(c("locA", "locB", "locC", "locD"), 100), 10, replace=T) # [1] "locD" "locD" "locD" "locD" "locB" "locA" "locA" "locA"
2009 Nov 21
7
consecutive numbering of elements in a matrix
Within a very large matrix composed of a mix of values and NAs, e.g, matrix A: [,1] [,2] [,3] [1,] 1 NA NA [2,] 3 NA NA [3,] 3 10 17 [4,] 4 12 18 [5,] 6 16 19 [6,] 6 22 20 [7,] 5 11 NA I need to be able to consecutively number, in new columns, the non-NA values within each column (i.e. A[1,1] A[3,2] and A[3,3] would all be set to one, and
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)