search for: newdf

Displaying 20 results from an estimated 90 matches for "newdf".

Did you mean: new_df
2003 Apr 07
4
subsetting a dataframe
How does one remove a column from a data frame when the name of the column to remove is stored in a variable? For Example: colname <- "LOT" newdf <- subset(olddf,select = - colname) The above statement will give an error, but thats what I'm trying to accomplish. If I had used: newdf <- subset(olddf,select = - LOT) then it would have worked, but as I said the column name is stored in a variable so I can't just enter it exp...
2011 Nov 11
2
One step way to create data frame with variable "variable names"?
...otherName" plotxRange <- c(10,20) modxVals <- c(1,2,3) It often happens I want to create a dataframe or object with plotx or modx as the variable names. But can't understand syntax to do that. I can get this done in 2 steps, creating the data frame and then assigning names, as in newdf <- data.frame( c(1, 2, 3, 4), c(4, 4, 4, 4)) colnames(newdf) <- c(plotx, modx) I was trying to hit this in one step, but can't find how. If I could get this in one step, it would simplify some book keeping, because this current method requires me to build up the name vector to match new...
2004 Jul 16
3
still problems with predict!
...)) x1<-rnorm(193) x2<-runif(193,-5,5) y<-rnorm(193)+x1+x2 p1<-as.data.frame(cbind(y,x1,x2)) p1 y x1 x2 1 -0.6056448 -0.1113607 -0.5859728 2 -4.2841793 -1.0432688 -3.3116807 ...... 192 -1.3228239 1.0263013 -2.7801324 193 1.8736683 1.0480632 0.4746959 newdf<-data.frame(x1= seq(min( p1$x1),max( p1$x1),length=10), x2=rep(median( p1$x2),10) ) pr<-predict(g<-lm(p1$y~p1$x1+p1$x2) ,newdf, se.fit = TRUE) newdf x1 x2 1 -2.3844149 -0.2594991 2 -1.8388635 -0.2594991 ... 9 1.9799963 -0.2594991 10 2....
2012 Feb 25
1
Unexpected behavior in factor level ordering
...efore Christ","After Christ")) y <- rnorm(6) m1 <- lm (y ~ xf ) plot(y ~ xf) abline (m1) ## Just a little problem the line does not "go through" the box ## plot in the right spot because contrasts(xf) is 0,1 but ## the plot uses xf in 1,2. xlevels <- levels(xf) newdf <- data.frame(xf=xlevels) ypred <- predict(m1, newdata=newdf) ##Watch now: the plot comes out "reversed", AC before BC plot(ypred ~ newdf$xf) ## Ah. Now I see: levels(newdf$xf) ## Why doesnt newdf$xf respect the ordering of the levels? -- Paul E. Johnson Professor, Politica...
2012 May 14
2
Error in names(x) <- value: 'names' attribute must be the same length as the vector
...s rows is not equal to zero if (nrow(NArows) != 0 ) { #find the rows in the current CSV file where there is missing data in prevdf (this info is in NArows) intersectItem<- intersect(currentCSVFile$Item, NArows$Item) #initiate another data frame to put the data in newdf.int <- data.frame(Item=c(), Color=c(), Number=c(), Size=c()) print(nrow(currentCSVFile)) for (i in 1:nrow(currentCSVFile)) { print("In loop") # check for me row <- currentCSVFile[i,] if (row$Item %in% intersectItem){ # this is where the...
2003 Sep 05
2
eliminating a large subset of data from a frame
...data frame with 155,000 rows. One of the columns represents the user id (of which about 10,000 are unique). I am able to isolate 1000 of these user ids (stored in a list) that I want to eliminate from the data set, but I don't know of an efficient way to do this. Certainly this would be slow: newdf<-df for(i in listofbadusers) { newdf<-subset(tmp,uid!=i) } is there a better approach? I guess I could use the opposite logic and use a list of good users and add their data to the new frame... thanks, pete
2018 Apr 27
5
predict.glm returns different results for the same model
...d, df = 5), data = dat, family = binomial) # The model coefficients are the same unname(coef(m1)) #> [1] 0.5194712 -0.8687737 -0.6803954 4.0838947 2.3908674 4.1564128 unname(coef(m2)) #> [1] 0.5194712 -0.8687737 -0.6803954 4.0838947 2.3908674 4.1564128 # But the predictions are not! newdf <- data.frame(wind = seq(min(dat$wind), max(dat$wind), length = 5)) unname(predict(m1, newdata = newdf)) #> [1] 0.51947119 0.03208719 2.82548847 3.90883496 4.06743266 unname(predict(m2, newdata = newdf)) #> [1] 0.5194712 -0.5666554 -0.1731268 2.8134844 3.9295814 Is this a bug? (Motiva...
2012 Apr 20
1
predictOMatic for regression. Please try and advise me
...bles in the focus list be drawn from this list: ", mfnames))) ## Consider "padding" range of fl for numeric variables so that we ## get newdata objects including the min and max values. mixAndMatch <- expand.grid(fl) mixAndMatch$combo <- 1:nrow(mixAndMatch) newdf <- cbind(mixAndMatch, modelcv[ ,!colnames(modelcv) %in% colnames(mixAndMatch)]) newdf } predictOMatic <- function(model = NULL, fl = NULL, ...){ nd <- newdataMaker(model, fl) fit <- predict(model, newdata=nd, ...) cbind(fit, nd) } set.seed(12345) x1 <- rnorm(10...
2005 Dec 07
4
Maintaining factors when copying from one data frame to another
...the archives, or in my notes (because I know I've encountered this in the past). My problem is: I have a data frame with columns A, B, C, D, and E. A, B, and E are factors and C and D are numeric. I need a new data frame with just A, C, and D. When I copy these columns to a new data frame >newDF <- data.frame(cbind(oldDF$A, oldDF$C, oldDF$D)) all the factor data comes out as levels rather than the original factors. How do I preserve the factors when I copy from one data frame to another? Thanks vary much, Kurt Wollenberg, Ph.D. Tufts Center for Vision Research Tufts-New England Medic...
2012 Jul 14
3
Can't understand syntax
...uot;]]))] test [["result"]] [!(is.na(test[["v3"]]))] <- test [["v3"]] [!(is.na (test[["v3"]]))] thanks! On Fri, Jul 13, 2012 at 6:41 AM, Rui Barradas <ruipbarradas@sapo.pt> wrote: > Hello, > > Check the structure of what you have, df and newdf. You will see that in > df dateTime is of class POSIXlt and in newDf newDateTime is of class > POSIXct. > > Solution: > > [...] > df$dateTime <- strptime(df$dateTime,"%m/%d/%Y %H:%M") > df$dateTime <- as.POSIXct(df$dateTime) > [...] > > Hope this hel...
2017 Jul 16
3
Arranging column data to create plots
...d. The imported data frame looks something like this (the actual file is huge, so this is example data) DF: IDKey X1 Y1 X2 Y2 X3 Y3 X4 Y4 Name1 21 15 25 10 Name2 15 18 35 24 27 45 Name3 17 21 30 22 15 40 32 55 I would like to create a new data frame with the following NewDF: IDKey X Y Name1 21 15 Name1 25 10 Name2 15 18 Name2 35 24 Name2 27 45 Name3 17 21 Name3 30 22 Name3 15 40 Name3 32 55 With the data like this I think I can do the following ggplot(NewDF, aes(x=X, y=Y, color=IDKey) + geom_line and get 3 lines with the various number of poin...
2011 Sep 21
1
Problem with predict and lines in plotting binomial glm
...ine to be predicted from the same x-values. I tried two ways of adding the newdata argument: ## a data.frame using the original x-values lines(x, predict(glm2, type= "response", newdata= as.data.frame(x))) ## or a data.frame with values (the same length as y) from the range of x values newdf <- data.frame(seq(min(x), max(x), length=52)) lines(x, predict(glm2, type="response", newdata= newdf)) Only the second option plotted a line once, but then I could never get it to do the same again on a new plot even though I used the same variables and same code. Thank you very muc...
2011 Aug 22
1
Selecting cases from matrices stored in lists
...1998 1 2 3 2 8029 1999 6 0 0 1"),head=TRUE,stringsAsFactors=FALSE)) a <- read.zoo(DF1, split = 1, index = 2, FUN = identity) sum.na <- function(x) if (any(!is.na(x))) sum(x, na.rm = TRUE) else NA b <- rollapply(a, 3, sum.na, align = "right", partial = TRUE) newDF <- lapply(1:nrow(b), function(i) prop.table(na.omit(matrix(b[i,], nc = 4, byrow = TRUE, dimnames = list(unique(DF1$B), names(DF1)[-1:-2]))), 1)) names(newDF) <- time(a) c<-lapply(newDF, function(mat) tcrossprod(mat / sqrt(rowSums(mat^2)))) DF2 = data.fra...
2017 Jul 16
0
Arranging column data to create plots
...3 17 21 30 22 15 40 32 55 That data is missing in X3 etc, but would be NA in an actual data frame, so I don't know if my workaround was the same as your workaround. Dput would have clarified the starting point. > I would like to create a new data frame with the following > > NewDF: > IDKey X Y > Name1 21 15 > Name1 25 10 > Name2 15 18 > Name2 35 24 > Name2 27 45 > Name3 17 21 > Name3 30 22 > Name3 15 40 > Name3 32 55 > > With the data like this I think I can do the following > > ggplot(NewDF, aes(x=X, y=Y, color...
2007 Oct 29
3
how to split data.frame by row?
hi, if I have 20 x 3 data.frame, how to split it into 10 x 6 (moving the lower part of 10x3 to column) or 5 x 12 thanks -- Weiwei Shi, Ph.D Research Scientist GeneGO, Inc. "Did you always know?" "No, I did not. But I believed..." ---Matrix III
2013 Feb 01
3
Transforming 4x3 data frame into 2 column df in R
I have the following data frame: > foo w x y z n 1.51550092 1.4337572 1.2791624 1.1771230 q 0.09977303 0.8173761 1.6123402 0.1510737 r 1.17083866 1.2469347 0.8712135 0.8488029 What I want to do is to change it into : > newdf 1 n w 1.51550092 2 q w 0.09977303 3 r w 1.17083866 4 n x 1.43375725 5 q x 0.81737606 6 r x 1.24693468 7 n y 1.27916241 8 q y 1.61234016 9 r y 0.87121353 10 n z 1.17712302 11 q z 0.15107369 12 r z 0.84880292 Whtat's the way t...
2008 Apr 23
2
Can I get rid of this for loop using apply?
Hey all, The code below creates a partial dependence plot for the variable x1 in the linear model y ~ x1 + x1^2 + x2. I have noticed that the for loop in the code takes a long time to run if the size of the data is increased. Is there a way to change the for loop into an apply statement? The tricky part is that I need to change the values of x1 in each step of the loop to give me the
2006 May 16
0
solution of split data.frame
...;,"D","C"), A1=c (1.2,1.2,2.4), A2=c(2,4,2.2) ) write.table(subset(myDF,select=c(V1,V2,A1)), file="foo.txt", row.name=FALSE, col.names = FALSE) write.table(subset(myDF,select=c(V1,V2,A2)), file="foo.txt", row.name=FALSE, col.names = FALSE, append= TRUE) newDF <- read.table("foo.txt", col.names=c("V1","V2","x")) newDF[1:10,] There's also the operating system solution if using Linux or Cywin/ Windows: myDF <- data.frame(V1=rep("A",3), V2=c("B","D","C"), A1=c (1.2,1...
2011 Jun 06
0
lme, stepAIC, predict: scope and visibility
...the lme object (and why is it even needed?). Here's some example code: foo = function() { x = c(1:20, 1:20) y = c(1:20, 5 + (1:20)) + rnorm(40) s = c(rep(1, 20), rep(2, 20)) library(lattice) xyplot(y~x|s) dframe = data.frame(x, y, s) m = lme(y~x, random=~1|s, method='ML') newdf = data.frame(x=40, s = 2) res = predict(m, newdata=newdf) print(res) m2 = stepAIC(m, k=log(nrow(dframe))) #res2 = predict(m2, newdata=newdf) res2 = eval(substitute(predict(mL, newdata=nL), list(mL=m2, nL=newdf))) print(res2) } > foo() 2 45.86875 attr(,"label") [1] &qu...
2005 Sep 08
5
data manipulation
Dear All, I would be grateful if you can help me. My problem is the following: I have a data set like: ID time X1 X2 1 1 x111 x211 1 2 x112 x212 2 1 x121 x221 2 2 x122 x222 2 3 x123 x223 where X1 and X2 are 2 covariates and "time" is the time of observation and ID indicates the