similar to: Subset according to groups NA proportion within specific variables

Displaying 20 results from an estimated 400 matches similar to: "Subset according to groups NA proportion within specific variables"

2010 May 25
1
Assigning NA to a rows of a dataframe/datamatrix
Dear R-users,  I have a problem, I have the following dataframe:   d<-data.frame(  'y1'=c(1,2,1,2,1,NA,NA), 'y2'=c(1,2,1,1,1,2,1), 'y3'=c(1,NA,1,NA,NA,2,1), 'y4'=c(NA,2,NA,1,1,2,NA), 'a'=c(1,1,1,1,1,1,2) ) where the last variable counts the number of missing values in a row. Now, i want to set rows where a>1 to NA and arrive at something like the
2008 Jul 07
5
Basic Vector and Matrix Operations
I am wondering if it is possible to perform the following two basic functions with primitive R functions. I know I could write functions for either, but it seems as though they are probably built-in somewhere. 1) Fill out a vector to a desired length with missing values or zeros. So, x<-c(3,4,5) f(x,5) 3,4,5,NA,NA 2) Find the [row,col] location of a particular value in a matrix, eg
2009 Mar 07
4
merge data frames with same column names of different lengths and missing values
Hello, I'm switching over from SAS to R and am having trouble merging data frames. The data frames have several columns with the same name, and each has a different number of rows. Some of the values are missing from cells with the same column names in each data frame. I had hoped that when I merged the dataframes, every column with the same name would be merged, with the value in a complete
2009 Dec 01
2
apply on two lists?
x=list(a=c(1,2),b=c(3,4,5)) y=list(a=c(1,2),b=c(3,4,5)) lapply(seq(along=x),function(i){cbind(x[[i]],y[[i]])}) I need to apply some function on two lists. I have to use the index to do as shown above. But I feel more natural to refer to the lists without using the index (using the syntax of something like, lapply(x,y, function(i,j){....})). I'm wondering if there is such a thing in R? Or
2010 Apr 05
3
Matrix elements are vectors
Dear all, My question how is it possible to define a matrix A with 10 rows 1 column, so that its elements are vectors of undefined length. I need to have a possibility later to add elements like A[1,1] <- c(A[1,1],3,4,5) Thanks a lot for the help! [[alternative HTML version deleted]]
2009 Dec 01
2
go back a block of code in history
Suppose I run the following code in the R session. At the last prompt '>', I want to retrieve the second command (staring with 'y'). But I have to type up arrow many times, which is very inconvenient. I'm wondering if there is a way to configure R to skip block of code in the history? > x=list(a=c(1,2),b=c(3,4,5)) > y=list(a=c(1,2),b=c(3,4,5)) > lapply(seq(along=x)
2009 Dec 01
2
go back a block of code in history
Suppose I run the following code in the R session. At the last prompt '>', I want to retrieve the second command (staring with 'y'). But I have to type up arrow many times, which is very inconvenient. I'm wondering if there is a way to configure R to skip block of code in the history? > x=list(a=c(1,2),b=c(3,4,5)) > y=list(a=c(1,2),b=c(3,4,5)) > lapply(seq(along=x)
2008 Aug 02
2
Gaps in time series.
I like the fact that in subtracting two time series objects that there is some effort to align the series. So if I have a time series of that begins at 1 and one that begins at 2 a subtraction operation makes sure that the proper values are subtracted. But I am unclear as to the best way to build a time series with "holes". say that I have data for "day" 1,2,6,7 in one time
2003 Aug 09
1
lm(), na.exclude and predict()
I'm trying to get predict.lm() to return an NA for each NA row in it's input vector, so the output is the same length as the input. I thought that using na.action=na.exclude with lm() would do that. But apparently not ?? df <- data.frame(x=c(NA,1,2,3,NA),y=c(0,2,3,4,0)) tl <- lm(y~x,df,na.action=na.exclude) predict.lm(tl,data.frame(x=c(2.5,NA,3,4,5))) 1 3 4 5 3.5 4.0 5.0
2003 Jan 31
3
hist (PR#2512)
The command hist(c(2,2,2,4,5,6)) returns a histogram that looks incorrect -- 3 in the bin labeled 2 on the left, but 1 each in the bins labeled 3,4,5 on the left. Thanks! Pam Surko -------------------- > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 1 minor
2012 Nov 24
5
subsetting - questions
Hello, I have two very basic questions (console attached): 1) What am I getting an error message for # 5 and # 7 ? 2) How to fix the code? I would appreciate receiving your help. Thanks, Pradip Muhuri ###### Reproducible Example ##### N <- 100 set.seed(13) df<-data.frame(matrix(sample(c(1:10),N, replace=TRUE),ncol=5)) keep_var <- c("X1", "X2") drop_var
2003 Feb 28
3
NULL object, R programming
Dear R users, I get the following (I think puzzling) result when doing the following: > a <- list(3,4,5) > a[[2]] <- NULL > a [[1]] [1] 3 [[2]] [1] 5 I would have expected the result to be: [[1]] [1] 3 [[2]] NULL [[3]] [1] 4 as in the outcome of: > list(3, NULL, 4) Is this a desired effect? If so, could it be built in a 'help(NULL)' file? If you think it is
2011 Aug 24
1
problema de selección de valores iniciales en nlm
Hola a todos, Necesito estimar dos parametros utilizando la función nlm; fit<-nlm(hood2par,c(x01[i],x02[j]),iterlim=300, catch=x[,c(3,4,5)],sp=.5) donde hood2par es una logística modificada. Pero en mi caso, la convergencia de nlm depende de los valores iniciales de dichos parámetros. Para buscar dichos valores iniciales de manera automática, genero dos vectores de valores iniciales
2013 Feb 03
2
Compare each element of a list to a vector
Hello R-helpers, I have a vector x<-c(1,2,3) and a list that contains vectors datalist<-list(c(1,2,3),c(2,3,4),c(3,4,5),c(4,5,6)) and I would like to identify those list elements that are identical to x. I tried > datalist %in% x [1] FALSE FALSE FALSE FALSE but I am obviously using %in% incorrectly. I also tried messing around with lapply but I can't figure out how to specify
2005 Oct 21
4
peculiar matrices
As far as I can tell from reading The Fine Documentation (R Language Definition and Intro to R), matrices are supposed to be of homogeneous types. Yet giving matrix() an inhomogeneous list seems to work, although it produces a peculiar object: v = list(1:3,4,5,"a") m = matrix(v,nrow=2) m [,1] [,2] [1,] Integer,3 5 [2,] 4 "a" m[1,] [[1]] [1] 1 2 3 [[2]]
2011 Jun 01
3
error in model specification for cfa with lavaan-package
Dear R-List, (I am not sure whether this list is the right place for my question...) I have a dataframe df.cfa
2009 Mar 06
2
How to apply a function to slices of multidimensional arrays, and not just iterating through single elements
Hello, If I want to apply some f(x) to such chunks of the the array dim(A)==c(d1,d2,d3,..,dk,...,dn) which are defined by A[...,ik,...] (ik belongs to {1,..,dk}), for now I use iteration via 'for (i in dim(A)[k]) f(A[...,k,...])' . Is there any more elegant approach, e.g like in 'apply' function which you can use on margin of the array. Just in my case I want the entire slice
2018 May 24
1
Predictions from a Cox model - understanding centering of binary/categorical variables
Dear all, I am using R 3.4.3 on Windows 10. I am preparing some teaching materials and I'm having trouble matching the by-hand version with the R code. I have fitted a Cox model - let's use the ovarian data as an example: library(survival) data(ovarian) ova_mod <- coxph(Surv(futime,fustat)~age+rx,data=ovarian) If I want to make predict survival for a new set of individuals at 100
2010 Oct 01
2
How to apply vector value function to a multidimensional array indexed by the remaining dimensions?
Hi, I am looking for some generalization of colSums and rowSums for general vector valued functions, and for arrays of more than 2 dimensions. So as a concrete example, suppose I have a 3 dimensional array, given by x = array(1:100,c(3,4,5)). and I want to sum the 3rd index of x to obain a 3 by 4 matrix. Using rowSums would return a vector of length 3 because it treats the last two indices as
2009 Feb 25
8
learning R
I was wondering why the following doesn't work: > a=c(1,2) > names(a)=c("one","two") > a one two 1 2 > > names(a[2]) [1] "two" > > names(a[2])="too" > names(a) [1] "one" "two" > a one two 1 2 I must not be understanding some basic concept here. Why doesn't the 2nd name change to