similar to: Summing up columns with NA elements in a data frame

Displaying 20 results from an estimated 20000 matches similar to: "Summing up columns with NA elements in a data frame"

2004 Dec 06
3
removing NA as a level
Dear R-helpers, I have a problem which I suppose is trivila, but... I have included NA values as factors ( (to be able to make nice printed summaries with NAs % ba category ) with the following code dat$x.f<-factor(dat$x, exclude=NULL); levels(dat$x.f)<-c("A1","A2","A3","A4","NA"); length(dat$x.f) Now, I want to impute the missing values.
2009 Jan 11
4
How to get solution of following polynomial?
Hi, I want find all roots for the following polynomial : a <- c(-0.07, 0.17); b <- c(1, -4); cc <- matrix(c(0.24, 0.00, -0.08, -0.31), 2); d <- matrix(c(0, 0, -0.13, -0.37), 2); e <- matrix(c(0.2, 0, -0.06, -0.34), 2) A1 <- diag(2) + a %*% t(b) + cc; A2 <- -cc + d; A3 <- -d + e; A4 <- -e fn <- function(z) { y <- diag(2) - A1*z - A2*z^2 - A3*z^3 - A4*z^4
2009 Oct 29
3
Removing & generating data by category
Dear R users, Basically, from the following arbitrary data set: a <- data.frame(id=c(c("A1","A2","A3","A4","A5"),c("A3","A2","A3","A4","A5")),loc=c("B1","B2","B3","B4","B5"),clm=c(rep(("General"),6),rep("Life",4))) > a
2010 Jun 17
3
ask a question about data sets element
for example, I have a1=c(1,3,5) a2=c(2,4,6) a3=c(7,8) a4=c(9,10) now if I have i=5, so i in a1, then I get a feedback tag[5]=1 i=8, so i in a3, then can get tag[8]=3 in there any function to do this to check the element belongs to which group? thank you!!! [[alternative HTML version deleted]]
2009 Apr 26
2
Help to select the raw in a data.frame with the max value
Dear User, thank for the attention. I have a data.frame with 5 columns (ex:ID, a1,a2,a3,a4) and 1000 rows. I wish to find the absolute max value for all data.frame and save a new data.frame with the row where is that value. Ex: ID: 1,2,3,4,5,6,7,8,9,10 a1:1,2,3,4,5,6,7,8,9,10 a2:11,12,13,14,15,16,17,18,19,20 a3:21,22,23,24,25,26,27,28,29,30 a4:31,32,33,34,35,36,37,38,39,40 The
2009 Sep 04
1
User defined function's argument as Subset function's input
Dear R users, I have a data where I desire to subset according to certain conditions. However, the script is very messy as there are about 30 distinct conditions. (i.e. same script but with different conditions) I would like to make a user defined function so that I can input the desired conditions and just get the results accordingly. Below is an arbitrary data set & sample statements
2005 Mar 19
2
simple problem, but not for me
Hello, I'm new in R and I want to do one thing that is very easy in excel, however, I cant do it in R. Suppose we have the data frame: data<- data.frame(A=c("a1","a2","a3","a4","a5")) I need to obtain another column in the same data frame (lets say B=c(b1,b2,b3,b4,b5) in the following way: b1=a1/(a1+a2+a3+a4+a5)
2004 Jul 08
2
Getting elements of a matrix by a vector of column indice s
See if the following helps: > m <- outer(letters[1:5], 1:4, paste, sep="") > m [,1] [,2] [,3] [,4] [1,] "a1" "a2" "a3" "a4" [2,] "b1" "b2" "b3" "b4" [3,] "c1" "c2" "c3" "c4" [4,] "d1" "d2" "d3" "d4" [5,]
2010 Apr 13
2
sensitivity analysis, input factors
Hi, I'm trying to conduct sensitivity analysis in R using the 'sensitivity' package. Although the description of functions seem straightforward, I can?t succeed. The definition of input factors can be the problem. library(sensitivity) #A simple model with 4 input factor to test the morris function: model01=function(a1,a2,a3,a4) { Z<-numeric(10) Z[1]<-runif(1)
2017 Oct 09
3
Merge me agrega siempre las columnas
Buenas, Tengo dos data.frames de la siguiente manera library(data.table) id<-c("a1","a2","a3","a4") id2<-c("a2","a3","a1","a4") y<-c(1,2,3,4) z<-c(3,5,6,7) k<-c(1,3,8,7) df1<-data.table(id,y,z) id<-c("a2","a3","a1","a4") df2<-data.table(id,x,y) Quiero
2018 May 27
1
if else with 4 conditions problem
Hi everyone, I have two columns: ? ?A? ? ? ? ? ? ? ?B ? ?1? ? ? ? ? ? ? ?1? ?1? ? ? ? ? ? ? ?0 ? ?0? ? ? ? ? ? ? ?1 ? ?0? ? ? ? ? ? ? ?0 I have 4 categories which are: 1) if A = 1 and B =1 then A1 = 1, else A2 = 0, A3 = 0, A4 = 0 2) if A = 1 and B =0 then A1 = 0, else A2 =1, A3 = 0, A4 = 0 3) if A = 0 and B = 1 then A1 = 0, else A2 = 0, A3 = 1, A4 = 0 4) if A = 0 and B =0 then A1 = 0, else A2 =
2008 Feb 10
2
reshape
Dear colleagues, I'd like to reshape a datafame in a long format to a wide format, but I do not quite get what I want. Here is an example of the data I've have (dat): sp <- c("a", "a", "a", "a", "b", "b", "b", "c", "d", "d", "d", "d") tr <- c("A",
2008 Mar 25
2
Compare two data sets
I would like to compare two data sets saved as text files (example below) to determine if both sets are identical(or if dat2 is missing information that is included in dat1) and if they are not identical list what information is different between the two sets(ie output "a1", "a3" as the differing information). The overall purpose would be to remove "a1" and
2013 Feb 07
1
Merging data in arrays
Dear All, Here is a hypothetical sample (sorry for the clumsy code): A1 <- matrix(1:5, nrow=5, ncol=1) A2 <- matrix(6:10, nrow=5, ncol=1) A3 <- matrix(11:15, nrow=5, ncol=1) A4 <- matrix(16:20, nrow=5, ncol=1) A5 <- matrix(21:25, nrow=5, ncol=1) A6 <- matrix(26:30, nrow=5, ncol=1) B1 <- matrix(c(A1, A2, A3), nrow=5, ncol=3) B2 <- matrix(c(A2, A3, A4), nrow=5, ncol=3) B3
2003 Dec 17
1
TODO hardlink reporting problem - fixed?
On Mon, 15 Dec 2003, jw schultz <jw@pegasys.ws> wrote: > OK, first pass on TODO complete. .... This hardlink bug report is nearly 21 months old... So I took a look at it using 2.5.7. See below. > BUGS --------------------------------------------------------------- > > Fix hardlink reporting 2002/03/25 > (was: There seems
2009 Jul 29
1
Subtract matrices within arrays along indices
I have the following array: 3 dimensional object, one dimension being year. Object is 3*3*3 library(plyr, reshape) a1<-rep(c(2007,2008,2009),9) a2<-c(rep("a",9),rep("b",9),rep("c",9)) a3<-c(rep(c(rep(1,3),rep(2,3),rep(3,3)),3)) a4 <- rnorm(27) A<-data.frame(cbind(comp=a2,val=a3, year=a1, a4)) A1<-melt(A, id=c("year", "comp",
2010 Sep 27
2
subtraction based on two groups in a dataframe
Hello I have a data set like below: plate.id well.id Group HYB rlt1 1 P1 A1 Control SKOV3hyb 0.190 2 P1 A2 Control SKOV3hyb 0.210 3 P1 A3 Control SKOV3hyb 0.205 4 P1 A4 Control SKOV3hyb 0.206 5 P1 A5 Control SKOV3hyb 0.184 385 P1 A1 ovca SKOV3hyb 0.184 386 P1 A2 ovca SKOV3hyb 0.229 387
2007 Feb 25
1
Repeated measures logistic regression
Dear all, I'm struggling to find the best (set of?) function(s) to do repeated measures logistic regression on some data from a psychology experiment. An artificial version of the data I've got is as follows. Firstly, each participant filled in a questionnaire, the result of which is a score. > questionnaire ID Score 1 1 6 2 2 5 3 3 6 4 4 2 ...
2007 Apr 05
2
Likelihood returning inf values to optim(L-BFGS-B) other options?
Dear R-help list, I am working on an optimization with R by evaluating a likelihood function that contains lots of Gamma calculations (BGNBD: Hardie Fader Lee 2005 Management Science). Since I am forced to implement lower bounds for the four parameters included in the model, I chose the optim() function mith L-BFGS-B as method. But the likelihood often returns inf-values which L-BFGS-B
2012 Sep 08
2
How to Rename Column Labels?
Hi, How do I rename the column labels in the table? For Instance, if I have a table like this, and I want to have the column labels changed from "A1 A2 A3 A4 A5" to "Mike Kate Michelle Paul Young" A1 A2 A3 A4 A5 1 33 44 55 66 77 2 3 4 5 6 7 7 8 9 and my text file location is: ""/Users/MAC/Desktop/data.txt" When I type in