search for: mydata

Displaying 20 results from an estimated 1626 matches for "mydata".

2012 Dec 07
2
Assigning cases to groupings based on the values of several variables
...my task is to simple: to assign cases to desired groupings based on the combined values on 2 variables. I can think of 3 methods of doing it. Method 1 seems to me pretty r-like, but it requires a lot of lines of code - onerous. Method 2 is a loop, so not very good - as it loops through all rows of mydata. Method 3 is a loop but loops through fewer lines, so it seems to me more efficient. Can you please tell me: 1. Which of my methods is more efficient? 2. Is there maybe an even more efficient r-like way of doing it? Imagine - "mydata" is actually a very tall data frame. Thanks a lot! Dimi...
2010 May 19
8
Generating all possible models from full model
...ult to alter models if I want to change a term. For example, below are the set of models I would like to run. Is there a way to specify the full model and have R generate the rest? I.e. specify m1234567<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) and have R run all the other models. library(MASS) #Intercept only m0<-glm.convert(glm.nb(mantas~1,data=mydata)) #One term - 7 models #Manta abundance is greater at one of the two sites m1<-glm.convert(glm.nb(mantas~site,data=mydata)) #Manta abundance increases each year as th...
2006 Nov 25
3
Multiple Conditional Tranformations
...ould like to check the logical state of gender only once and create both (or any number of) scores at once. mystring<- ("id,group,gender,q1,q2,q3,q4 01,1,f,2,2,5,4 02,2,f,2,1,4,5 03,1,f,2,2,4,4 04,2,f,1,1,5,5 05,1,m,4,5,4, 06,2,m,5,4,5,5 07,1,m,3,3,4,5 08,2,m,5,5,5,4") mydata<-read.table(textConnection(mystring),header=TRUE,sep=",",row.name s="id") mydata #Create score1 so that it differs for males and females: mydata$score1 <- ifelse( mydata$gender=="f" , (mydata$score1 <- (2*mydata$q1)+mydata$q2), ifelse( mydata$g...
2004 Aug 17
5
Bug in colnames of data.frames?
Hi, I am using R 1.9.1 on on i686 PC with SuSE Linux 9.0. I have a data.frame, e.g.: > myData <- data.frame( var1 = c( 1:4 ), var2 = c (5:8 ) ) If I add a new column by > myData$var3 <- myData[ , "var1" ] + myData[ , "var2" ] everything is fine, but if I omit the commas: > myData$var4 <- myData[ "var1" ] + myData[ "var2" ] the name...
2005 Jun 16
5
Vectorization
Greetings, Can anyone suggest me if we can vectorize the following problem effectively? I have two datasets, one dataset is portfolio of stocks returns on a historical basis and another dataset consist of a bunch of factors (again on a historical basis). I intend to compute a rolling n-day sensitivitiesfor each stock for each factor, so the output will be a data frame with
2010 Apr 05
2
find the "next non-NA" value within each row of a data-frame
#I wish to find the "next non-NA" value within each row of a data-frame. #e.g. I have a data frame mydata. Rows 1, 2 & 3 have soem NA values. mydata <- data.frame(matrix(seq(20*6), 20, 6)) mydata[1,3:5] <-  NA mydata[2,2:3] <-  NA mydata[2,5] <-  NA mydata[3,6] <-  NA mydata[1:3,] #this loop accomplishes the task; I am tryign toi learn a "better" way for(i in (ncol(mydat...
2012 Mar 28
3
Connect lines in a dot plot on a subject-by-subject basis
I am trying to plot where data points from a give subject are connected by a line. Each subject is represented by a single row of data. Each subject can have up to five observations. The first five columns of mydata give the time of observation, columns 6-10 give the values at each time point. Some subjects have all data, some are missing values. The code I wrote to draw the plot is listed below. If you run the code you will see that (1) The few lines drawn are not drawn on a subject-by-subject basis, (2) not...
2012 Jul 17
1
problem with function
Dear list, I have a problem with defining a function (see below) to read my testfile (see testfile). My function only returns mydata I wish to work with attr(mydata, 'fc') as well (for labelling a plot). Principally it works if I do not insist on this function but it would be much easer if it is possible to return mydata AND attr(mydata, 'fc') by using a function. 1) testfile: Id;fc;zat;dat;hat PG;1,3;1;2;3 HU;...
2009 Sep 04
2
lrm in Design package--missing value where TRUE/FALSE needed
Hi, A error message arose while I was trying to fit a ordinal model with lrm() I am using R 2.8 with Design package. Here is a small set of mydata: RC RS Sex CovA CovB CovC CovD CovE 2 1 0 1 1 0 -0.005575280 2 2 1 0 1 0 1 -0.001959580 2 3 0 0 0 1 0 -0.004725880 2 0 0 0 1 0 0 -0.005504850 2 2 1 1 0 0 0 -0.003880170 1 2 1 0 0 1 0 -0.006074230 2 2 1 0 0 1 1 -0.003963920 2 2 1 0 0 1 0 0.000658230 2 2 1 0 1 0 1 -0.002033610 2 0 0 0 0 0 1 -0....
2005 Jul 19
1
S4 Dispatching
...dispatch. Example code below omits multiple parameters that can be different types. Essentially, any parameter would be converted to an internal type "class" and the final dispatch would be passing EXTPTRSXP objects. library(methods) setGeneric("onthefly", function(mydata) { cat("generic", match.call()[[1]], "\n") standardGeneric("onthefly") }) setMethod("onthefly", signature(mydata = "character"), function(mydata) { cat(match.call()[[1]], "(character)\n") # Sim...
2008 Jan 03
2
retaining formatting when converting a vector to a matrix/data.frame?
Please see example code below. I have a vector ("mydata") of length 10. "mydata" can have various formats (e.g. numeric, text, POSIXct, etc) I use the matrix and data.frame functions to convert "mydata" to a dataframe ("mydf") of 2 columns and 5 rows. What is a "good" way to ensure that the format is...
2013 Dec 16
1
External pointers and changing SEXPTYPE
...d_my_data(a) data structure in C: typedef struct { SEXP ans, ans_nms, R_z, R_a, R_b, R_c; FTYPE *datafile; char *fname; float *a, *b, *c; int f_type; float t, p, l; int st, na, result, bFlags; XXX z; } my_data_ptr; // In a C function initializing the external pointer: my_data_ptr *mydata = Calloc( 1, my_data_ptr ) ; SEXP Rdata; PROTECT(Rdata = R_MakeExternalPtr( mydata, R_fname, R_NilValue )); ... mydata->a = Calloc(mydata->na, float); // same for b and c // initializing names so that I could use e.g. df$a where df is returned by read_my_data() PROTECT(mydata->ans_nms = Rf...
2007 Jun 15
2
model.frame: how does one use it?
...a and supporting arguments, in particular 'weights'. A simple contrived example is ----------------------------------------------------------------------------- library(rpart) ## using data from help(rpart), set up simple example myformula <- formula(Kyphosis ~ Age + Number + Start) mydata <- kyphosis myweight <- abs(rnorm(nrow(mydata))) goodFunction <- function(mydata, myformula, myweight) { hyp <- rpart(myformula, data=mydata, weights=myweight, method="class") prev <- hyp } goodFunction(mydata, myformula, myweight) cat("Ok\n") ## now remove...
2008 May 16
1
xyplot: subscripts, groups and subset
I have stumbled across something in the Lattice package that is vexing me. Consider the code below: __________________________________________________________ library(lattice) myData <- expand.grid(sub = factor(1:16), time = 1:10) myData$observed <- rnorm(nrow(myData)) myData$fitted <- with(myData, ave(observed, sub, FUN = mean)) myData$event.time <- with(myData, ave(observed, sub, FUN = function(.x) 10 * runif(1))) myData <- myData[order(myData$sub, myData$tim...
2010 Oct 06
3
tapply output
...lt;- c(2008, 2009, 2008, 2009, 2008, 2009, 2008, 2009); group <- c('A', 'A', 'B', 'B', 'A', 'A', 'B', 'B'); class <- c(0, 0, 0, 0, 1, 1, 1, 1); height <- c(62, 63, 59, 58, 67, 66, 70, 71); #Combine the data into a data frame; myData <- data.frame(name, year, group, class, height); myData; #Calculate the mean of height by class, group, and name; tapply(myData$height, data.frame(myData$class, myData$group, myData$name), mean); #The raw output from the tapply function is fine, but I would; #really like the output to look lik...
2007 Mar 07
5
how to "apply" functions to unbalanced data in long format by factors......cant get "by" or "aggregate" to work
...rmat that does not contain balanced data. The ID is a unique identifier corresponding to the experimental unit that will later be examined by ANOVA, T-tests etc. Y is the data generated from the experiment. The factors represent the differences between each sample or "run" measured. str(mydata) ### sample of table at bottom of email ### 'data.frame': 129982 obs. of 6 variables: $ ID : num 7 7 7 7 7 7 8 8 8 8 ... $ time : Factor w/ 2 levels "120hr","24hr": 1 1 1 1 2 2 2 1 1 1 ... $ treatment: Factor w/ 2 levels "control","trt"...
2012 Apr 12
4
Recode Variable
Ein eingebundener Text mit undefiniertem Zeichensatz wurde abgetrennt. Name: nicht verf?gbar URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120412/74331e9a/attachment.pl>
2004 Mar 26
1
Mahalanobis
Dear all Why isn'it possible to calculate Mahalanobis distances with R for a matrix with 1 row (observations) more than the number of columns (variables)? > mydata <- matrix(runif(12,-5,5), 4, 3) > mahalanobis(x=mydata, center=apply(mydata,2,mean), cov=var(mydata)) [1] 2.25 2.25 2.25 2.25 > mydata <- matrix(runif(420,-5,5), 21, 20) > mahalanobis(x=mydata, center=apply(mydata,2,mean), cov=var(mydata)) [1] 19.04762 19.04762 19.04762 19.04762 19...
2009 Sep 03
2
dividing a dataframe column by different constants
...on hundred. It is known that at the minimum time is present the maximum concentration, by which divide all the other concentrations in the sample. I'm quite sure that there's a more elegant solution, but I really do not even imagine how to write it. Thanks in advance for your time (df.mydata <- data.frame( CONC = c(seq( from = 1, to = 0.1, by = -0.1 ), seq( from = 0.8, to = 0.2, by = -0.1 ), seq( from = 0.6, to = 0.1, by = -0.05 )), TIME =...
2013 Jun 10
1
padding specific missing values with NA to allow cbind
Dear list Getting very frustrated with this simple-looking problem > m1 <- lm(x~y, data=mydata) > outliers <- abs(stdres(m1))>2 > plot(x~y, data=mydata) I would like to plot a simple x,y scatter plot with labels giving custom information displayed for the outliers only, i.e. I would like to define a column mydata$labels for the mydata dataframe so that the command > text(myd...