similar to: Finding the column with the maximum value by row

Displaying 20 results from an estimated 70000 matches similar to: "Finding the column with the maximum value by row"

2012 Apr 09
3
For loops
Hi, I am having trouble with syntax for a for loop. Here is what I am trying to do. class=c(rep(1,3),rep(2,3),rep(3,3)) out1=rnorm(length(class)) out2=rnorm(length(class)) out3=rnorm(length(class)) data=data.frame(class,out1,out2,out3) dat.split=split(data,data$class) for(i in 1:3){ sub[i]=dat.split[i] } However, the for loop doesn't work. I want to assign each split to a different
2009 Mar 12
3
Unable to run smoother in qplot() or ggplot() - complains about knots
I get the following error when I run qplot() qplot(grade, read,data = hhm.long.m, geom = c("point", "smooth")) Error in smooth.construct.cr.smooth.spec(object, data, knots) : x has insufficient unique values to support 10 knots: reduce k. I am not sure how to tackle this problem. When I take a subsample (< 1000) than I am able to run that function but with my sample
2010 Apr 09
3
How to replace all non-maximum values in a row with 0
Hi, I would like to replace all the max values per row with "1" and all other values with "0". If there are two max values, then "0" for both. Example: from: 2 3 0 0 200 30 0 0 2 50 0 0 3 0 0 0 0 8 8 0 to: 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 Thanks! -- View this message in context:
2011 Mar 30
6
Quick recode of -999 to NA in R
Hi, I am trying to write a loop to recode my data from -999 to NA in R. What's the most efficient way to do this? Below is what I'm presently doing, which is inefficient. Thanks, Chris dat0 <- read.table("time1.dat") colnames(dat0) <- c("e1dq", "e1arcp", "e1dev", "s1prcp", "s1nrcp", "s1ints",
2010 Jul 22
2
Multilevel survival model
* Please cc me if you reply as I am a digest subscriber * Hi, I am wondering how I can run a multilevel survival model in R? Below is some of my data. > head(bi0.test) childid famid lifedxm sex age delta 1 22.02 22 CONTROL MALES 21.36893 0 2 13.02 13 MAJOR MALES 21.18001 0 3 64.02 64 CONTROL MALES 20.09377 0 4 5.02 5 CONTROL FEMALES
2012 Jul 20
2
Changing ungrouped cases to grouped cases
Hi, I have my data the following way: y A B C 0 1 1 2 0 1 2 1 1 1 1 2 0 1 1 2 1 1 1 2 1 1 2 1 0 1 2 2 . . . And so on. How can I make my data look like the following: y A B C 2 1 1 2 1 1 2 1 0 1 2 2 . . . In other words how can I change my ungrouped cases into grouped cases? Thanks! Chris [[alternative
2010 Jul 23
1
Survival analysis MLE gives NA or enormous standard errors
Hi, I am trying to fit the following model: sr.reg.s4.nore <- survreg(Surv(age_sym4,sym4), as.factor(lifedxm), data=bip.surv) Where age_sym4 is the age that a subject develops clinical thought problems; sym4 is whether they develop clinical thoughts problems (0 or 1); and lifedxm is mother's diagnosis: BIPOLAR, MAJOR DEPRESSION, or CONTROL. I am interested in whether or not
2011 Mar 29
4
Creating 3 vectors that sum to 1
I have 3 vectors: p1, p2, and p3. I would like each vector to be any possible value between 0 and 1 and p1 + p2 + p3 = 1. I want to graph these and I've thought about using scatterplot3d(). Here's what I have so far. library(scatterplot3d) p1 <- c(1,0,0,.5,.5,0,.5,.25,.25,.34,.33,.33,.8,.1,.1,.9,.05,.05) p2 <- c(0,1,0,.5,0,.5,.25,.5,.25,.33,.34,.33,.1,.8,.1,.05,.9,.05) p3 <-
2012 Mar 29
1
Retrieving matrix column and row names by index value
Hi all, So let's say I have a matrix, mdat and I only know the index number. How do I retrieve the column and row names? For example, > mdat <- matrix(c(1,2,3, 11,12,13), nrow = 2, ncol=3, byrow=TRUE, dimnames = list(c("row1", "row2"), c("C.1", "C.2", "C.3"))) > mdat[4] [1] 12 >
2011 Apr 06
3
Getting number of students with zeroes in long format
Hi, I have longitudinal school suspension data on students. I would like to figure out how many students (id_r) have no suspensions (sus), i.e. have a code of '0'. My data is in long format and the first 20 records look like the following: > suslm[1:20,c(1,7)] id_r sus 11 0 15 10 16 0 18 0 19 0 19 0 20 0 21 0 21 0 22 0 24 0 24
2009 Mar 19
2
Randomly splitting a data frame in half
I have a data frame in long format and I would like to randomly divide this data frame in half. The data frame consists of 39622 rows and I initially tried ... randomsample1 <- data[sample(nrow(data),19811), ] Where allows me to randomly select half of the rows and assign them to randomsample1 but then I couldn't figure out how to select those rows that were not selected and assign
2010 May 28
3
Gelman 2006 half-Cauchy distribution
Hi, I am trying to recreate the right graph on page 524 of Gelman's 2006 paper "Prior distributions for variance parameters in hierarchical models" in Bayesian Analysis, 3, 515-533. I am only interested, however, in recreating the portion of the graph for the overlain prior density for the half-Cauchy with scale 25 and not the posterior distribution. However, when I try:
2012 Nov 03
2
Replacing NAs in long format
Hi, I have the following data: > data[1:20,c(1,2,20)] idr schyear year 1 8 0 1 9 1 1 10 NA 2 4 NA 2 5 -1 2 6 0 2 7 1 2 8 2 2 9 3 2 10 4 2 11 NA 2 12 6 3 4 NA 3 5 -2 3 6 -1 3 7 0 3 8 1 3 9 2 3 10 3 3 11 NA What I want to do is
2011 May 19
1
Finding row in matrix with minimum column
Friends If I have a matrix such as... [,1] [,2] [1,] 7 7 [2,] 7 9 [3,] 9 2 [4,] 7 9 And I want to find the row number that has the minimum value of column 2 (row 3 in this case) how can I do it? Is there a simple way? cheers Worik [[alternative HTML version deleted]]
2010 Apr 18
2
Calculating a Maximum for a row or column with NA's
Is there a simple way to calculate the maximum for a row or column of a matrix when there are NA,s present. # given a matrix that has any number of NA per row > m<-matrix(c(seq(1,9)),nrow=3) > m [,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 > m[3,1]=NA > m[1,]=NA > m [,1] [,2] [,3] [1,] NA NA NA [2,] 2 5 8 [3,] NA 6 9
2010 May 13
1
Questions about ggplot2
Hi I have two questions about using ggplot2. First, I have multiple columns of data that I would like to combine into one histogram where each column of data would correspond to one bar in the histogram. Each column has 0 or 1s and I want my bars in the histogram to correspond to the sum of the 1s in each column. Does that make sense? Second, is there a way to completely turn off the legend?
2009 Jun 28
1
ggplot2 x axis question
Hi, I have 45 models that I have named: 1, 2, 3, ... , 45 and I am trying to plot them in order of ascending BIC values. I am however unclear as to how I can get the models to line up on the x-axis by BIC and not by numeric order. For example, if model 5 has a lower BIC than 1, I want it to be the first point on the left hand side of the curve. This seems to work in plot: plot(1:45,
2009 Jun 28
1
ggplot2 x axis question
Hi, I have 45 models that I have named: 1, 2, 3, ... , 45 and I am trying to plot them in order of ascending BIC values. I am however unclear as to how I can get the models to line up on the x-axis by BIC and not by numeric order. For example, if model 5 has a lower BIC than 1, I want it to be the first point on the left hand side of the curve. This seems to work in plot: plot(1:45,
2012 Sep 21
1
New Submission to CRAN note
Hi, I want to submit a package to CRAN and I am getting the following Note: * checking CRAN incoming feasibility ... NOTE New submission How can I take care of this? And/or is it a big deal? Thanks and sorry if this is something that I easily overlooked I have googled this topic for a while and found nothing. Chris [[alternative HTML version deleted]]
2011 Aug 04
1
Plotting just a portion of a smoother graph in ggplot2
Hi, I am using ggplot2 to with the following code: gmathk2 <- qplot(time,math,colour=Kids,data=kids.ach.lm.k5,geom="smooth",method="lm",formula=y~ns(x,1)) + opts(title="Smoother Plot: Math K-5") + xlab("Time") + ylab("Math") + scale_colour_brewer(pal="Set1"); gmathk2 This plots all the smoother for all the x values. What I'd like