search for: idvar

Displaying 20 results from an estimated 241 matches for "idvar".

Did you mean: indvar
2007 Sep 07
2
R first.id last.id function error
...<- (Lag(file1$id) != file1$id) file1$last.id[1]<-TRUE #force NA to TRUE #resort to original order file1<- file1[order(file1$id,file1$week),] I am now trying to get the above code to work as a function, and am clearly doing something wrong: > first.last <- function (df, idvar, sortvars1, sortvars2) + { + #sort in ascending order to define first dot + df<- df[order(sortvars1),] + df$first.idvar <- (Lag(df$idvar) != df$idvar) + #force first record NA to TRUE + df$first.idvar[1]<-TRUE + + #sort in descending order to define last dot + df<- df[or...
2009 Oct 21
1
formula and model.frame
Suppose I have the following function myFun <- function(formula, data){ f <- formula(formula) dat <- model.frame(f, data) dat } Applying it with this sample data yields a new dataframe: qqq <- data.frame(grade = c(3, NA, 3,4,5,5,4,3), score = rnorm(8), idVar = c(1:8)) dat <- myFun(score ~ grade, qqq) However, what I would like is for the resulting dataframe (dat) to include as a column idVar. Naively, I could do dat <- myFun(score ~ grade + idVar, qqq) This gives what I'm after in terms of the resulting data, but doesn't make sense wi...
2005 Oct 31
0
Problem using reshape with missing values in idvar
...t;- read.csv("df.csv") # Read .csv file into R df.tt <- sequence(rle(df$ID)$length) # Create a sequence vector tt based on the number of times ID appears # Then reshape from long into wide format, with only the time-varying variables repeated df_wide <- reshape(cbind(df.tt,df), idvar("ID","DOB","GENDER","ETHNICITY"), timevar="tt",direction="wide") This testcase works fine. Now taking a similar test case, with some missing values in the idvar, like so, ID DOB GENDER ETHNICITY TESTDATE TESTRESULT 1 1/1/1900 1 1 1/...
2009 Feb 08
0
Modifying forestplot function in rmeta
...1$last.id[1]<-TRUE #force NA to TRUE > >#resort to original order >file1<- file1[order(file1$id,file1$week),] > > > >I am now trying to get the above code to work as a function, and am >clearly doing something wrong: > > > first.last <- function (df, idvar, sortvars1, sortvars2) >+ { >+ #sort in ascending order to define first dot >+ df<- df[order(sortvars1),] >+ df$first.idvar <- (Lag(df$idvar) != df$idvar) >+ #force first record NA to TRUE >+ df$first.idvar[1]<-TRUE >+ >+ #sort in descending order to d...
2001 Dec 27
3
reshape error in 1.4 (PR#1231)
...:0.250 Min. :0.0500 4:11 1st Qu.:0.750 1st Qu.:0.1100 2:11 Median :2.000 Median :0.3400 5:11 Mean :2.886 Mean :0.5918 6:11 3rd Qu.:5.000 3rd Qu.:0.8325 3:11 Max. :8.000 Max. :2.7200 > wide<-reshape(Indometh,v.names="conc",idvar="Subject", + timevar="time",direction="wide") Error in tapply(a, data[, idvar], function(b) length(unique(b)) == 1) : arguments must have same length > version _ platform i386-pc-mingw32 arch x86 o...
2009 Sep 14
2
problems with reshape
...03 2 1033 1 54872XXXXXX FLGOIP66A3XXXXXX 2000-11-28 3 1043 2 56849XXXXXX QPWOER52E2XXXXXX 2000-07-07 4 1508 2 54982XXXXXX FJKLSD67P4XXXXXX 2000-12-12 5 1532 2 56849XXXXXX QWERTG50T0XXXXXX 2000-03-30 6 3283 1 12345XXXXXX POIQWE74H0XXXXXX 1999-12-31 Sil_cf and sil_pi are the idvar (sensible data too), prog is the timevar (now dataset is not sorted) > sapply(rl, class) id_rl prog sil_pi sil_cf sil_dat_avv "integer" "integer" "character" "character" "Date" > apply(rl, 2, function(x) sum...
2005 Mar 26
1
Function Arguments
Hello, I am trying to wrap some code that I repeatedly use into a function for efficiency. The following is a toy example simply to illustrate the problem. foobar.fun<-function(data,idvar,dv){ id.list<-unique(idvar) result<-numeric(0) for (i in id.list){ tmp1<-subset(data, idvar == i) result[i]<-mean(get("tmp1")[[dv]]) } return(result) } The issue is that when the variable 'dv' is replaced by the name of the actual variable in the...
2012 Dec 06
1
scope, lme, ns, nlme, splines
...low provides a clumsy solution. It turns the lme() command, along with the appropriate value of splineDF, into a text string and then uses eval(parse(text=mystring)). But is there not a more elegant solution? set.seed(5) junk<-data.frame(x=rnorm(100)) junk$y<-junk$x + rnorm(nrow(junk)) junk$idvar<- factor(sample(LETTERS[1:10], size=nrow(junk), replace=TRUE)) library("nlme") library(splines) fitfunction<-function(splineDF=1) { thislm<-lm( y ~ ns(x, df=splineDF), data= junk) thislm cat("finished thislm\n") thislme<-lme( fixed= y ~ ns(x, df=splineDF)...
2000 Sep 29
0
Is it R or I?
...CEC + CLAY + ERODFAC +INCEPTSL + JANT + JARPPET + JULT + MAXELV + MAYSEPT + MINELV + MOLLISOL + OM + PERM + PET + PH + PPT + PROD + ROCKDEP + ROCKFRAG + SLOPE + SPODOSOL + TAWC + TEXCOARS + TEXFINE + ULTISOL", pickedlist="BD + CEC + CLAY + ERODFAC + INCEPTSL", resp="iv802", idvar="FIPS") Reading in data DONE Reading in data Lm Model Done building model Plotting the model output DONE-Plotting the model output Before tcltk Segmentation fault (core dumped) NOTE: Sometimes the program runs (very slowly) without segmentation fault... File -> eda_lmtst.rf NOTE: pic...
2006 Jan 22
6
Making a markov transition matrix
...uot;,"f1","f2","f2","f2","f2"), year=c(83, 84, 85, 86, 83, 84, 85, 86), state=sample(1:3, 8, replace=TRUE) ) # Shift to wide format -- fixedup <- reshape(raw, timevar="year", idvar="name", v.names="state", direction="wide") # Now tediously build up records for an intermediate data structure try <- rbind( data.frame(prev=fixedup$state.83, new=fixedup$state.84), data.frame(prev=fixedup$state.84, new=f...
2009 Oct 04
2
Row to Column help
...tmt.1 tmt.2 alliance.1 alliance.2 alliance.3 1 j cbt NA wai NA NA 2 k act dbt other calpas NA 3 l act act wai itas other I tried: > wide <- reshape(data, idvar=c("id","author"), direction="wide") Error in `[.data.frame`(data, , timevar) : undefined columns selected If I specify all columns, it gives the following format (which is not desired): wide <- reshape(data, idvar=c("id","author"), + direction...
2003 Oct 30
1
Trouble reshaping some data
...lt;- data.frame(id=c(1,1,2,2), aspect=c("A","B","A","B"), score=c(10,9,11,12)) I'd like it to look like this: id A B 1 10 9 2 11 12 reshape() looks like a good candidate for this job but I'm not really sure about the roles of timevar and idvar for this dataframe. I tried t2 <- reshape(t1, direction="wide", timevar=t1[,3], idvar=t1[,2]) which is obviously ignorant and wrong. Thank you in advance for any comments. Regards, Andrew C. Ward CAPE Centre Department of Chemical Engineering The University of Qu...
2011 Jan 11
1
sorting question
...CET"). Now, I want to sort the data frame in ascending order by a, b, c and then in descending order by t. Here's what I've got, but I'm not sure how to put the 'descending' bit in the code. The trick with the minus sign doesn't work as the var isn't numeric. idvars <-- c("a", "b", "c") myData["t"] <- as.POSIXct(myData[,"t"]) result <- myData[ do.call(order, myData[c(idvars, "t")]), ] This should be simple, I guess, but I've been staring at this a bit too long now. Suggestions anyone?...
2006 Jan 23
0
Making a markov transition matrix - more progress
...uot;,"f1","f2","f2","f2","f2"), year=c(83, 84, 85, 86, 83, 84, 85, 86), state=sample(1:3, 8, replace=TRUE) ) # Shift to wide format -- fixedup <- reshape(raw, timevar="year", idvar="name", v.names="state", direction="wide") # Now tediously build up records for an intermediate data structure tmp <- rbind( data.frame(prev=fixedup$state.83, new=fixedup$state.84), data.frame(prev=fixedup$state.84, new=f...
2013 Apr 08
1
remove duplicates in data frame
Hi, Try ?unique() You haven't provided reproducible data or information about the package.? So, this may or may not work. dat1<- data.frame(idvar=c(rep(1,2),2,4),col2=c(7,7,8,9)) ?dat1 #? idvar col2 #1???? 1??? 7 #2???? 1??? 7 #3???? 2??? 8 #4???? 4??? 9 ?unique(dat1) #? idvar col2 #1???? 1??? 7 #3???? 2??? 8 #4???? 4??? 9 A.K. I got the following message when trying to use Google motion charts. Error in gvisCheckMotionChartData(data,...
2009 Dec 09
1
reshape() makes R run out of memory (PR#14121)
...uot; transpose) based on common ID and DATEs: ID DATE1 DATE2 VALUE.TYPE1 VALUE.TYPE2 'abcd1233' 2009-11-12 2009-12-23 123.45 NA ... Using stock reshape() as follows: tbl2 <- reshape(tbl, direction = "wide", idvar = c("ID", "DATE1", "DATE2"), timevar = "VALUE_TYPE"); On a toy data frame this works fine. On a real one with 4.7 million entries (although about 70% of VALUEs are NA) it runs out of memory: Error: cannot allocate vector of size 4.8 Gb When the real da...
2012 Dec 11
1
Debian packaging and openblas related crash when profiling in R
...but only when openblas stuff is in the picture. I wondered what you think? Here's the code to reproduce this: datM <- read.csv("http://pj.freefaculty.org/scraps/profile/missingDat.csv") library(Amelia) set.seed(12345) Rprof("Amelia-1.out") impA <- amelia(datM, m = 5, idvars="group") Rprof(NULL) summaryRprof("Amelia-1.out") Here's the crashed session > datM <- read.csv("http://pj.freefaculty.org/scraps/profile/missingDat.csv") > library(Amelia) Loading required package: foreign ## ## Amelia II: Multiple Imputation ## (Vers...
2004 Aug 06
1
reshape (was: Comparing rows in a dataframe)
...2 2001 100010 19 Grade 4 2 2002 100010 20 Grade 4 2 2003 100010 22 Grade 5 2 2001 100010 Now, I want to reshape this into the wide format. However, when I do I get NAs in the stability columns. Here is what I have done and the result. wide<- reshape(tennshort, idvar = c("schid","grade"), timevar = "year", v.names="stability", direction="wide") grade schid stability.2001 stability.2002 stability.2003 6 Grade 4 100005 NA NA NA 10 Grade 5 100005 NA...
2008 Nov 18
1
reshape question
Hi, It's probably a simple issue but I'm struggling with that. I'll use the example shown in the help page. head(Indometh) wide <- reshape(Indometh, v.names="conc", idvar="Subject", timevar="time", direction="wide") head(wide) reshape(wide, idvar="Subject", varying=list(2:12), v.names="conc", direction="long") but, in my case I'll like the "time" column be filled with...
2011 Jul 22
0
Using package amelia
...nth, measurements, standard deviation of the measurement). Of course, there are some random missing values on columns 3 and 4. The measurements are an almost periodic time-series contaminated by noise. I did some tests such as: a.out <- amelia(x, m = 5, ts = "YEAR", p2s = 0, idvars=c("DEV")); > a.out <- amelia(x, m = 5, ts = "YEAR", p2s = 0, idvars=c("MON","DEV")); Error in matrix(1, AMn, 1) : non-numeric matrix extent a.out <- amelia(x, m = 5, ts = "YEAR", p2s = 0); a.out <- amelia(x, m = 5, p2s = 0, id...