search for: testdf

Displaying 20 results from an estimated 39 matches for "testdf".

Did you mean: test_f
2009 Sep 16
3
apply function across two variables by mult factors
...using by(X, list(factor1, factor2), function), however I haven't found a simple way to extract the list output into an organized vector form. I can do this using nested loops but it isn't exactly an optimal approach. Thank you for any and all suggestions. Jon # example data frame testDF<-data.frame( x=rnorm(12), y=rnorm(12), f1=gl(3,4), f2=gl(2,2,12)) # example function [trivial] testFun<-function(x){ X<-abs(x[,1]); Y<-abs(x[,2]); as.numeric( paste(round(X), round(Y), sep='.')) } # apply by factor levels but hard to extract values by(testDF[,1:2], lis...
2009 Mar 20
4
how to make aggregation in R ?
Hi, I am trying to aggregate the sum of my test data.frame as follow: testDF <- data.frame(v1 = c("a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "c", "c", "c", "c", "c", "d", "d", "d", &quot...
2011 Mar 09
2
SQLDF - Submitting Queries with R Objects as Columns
...SQLDF needs to understand that when I reference "var1", it should look for "X" in the dataframe. This is necessary because my SQLDF is part of a larger function that I call that repeatedly with different column names. Code below... thank you in advance! Mike library(sqldf) testdf<-data.frame(c(1,2,3,4,5,6,7,8,9,10),c(1,1,1,2,2,2,3,3,3,3)) names(testdf)<-c("X","Y") # Works as intended sqldf("select sum(X) as XSUM, Y as Y from testdf group by Y") # Now... can I reference var1 in the code? var1<-"X&...
2010 Sep 18
0
Saving long character variable to database saves timestamp instead
...rs, to a text field in PostgreSQL, using RODBC on Windows XP, I get a timestamp saved to the database instead. Is there any way to extend the number of characters that a text variable can receive? Here are the details of my case (simplified): I'm using PostgreSQL to create a table CREATE TABLE testdf ( numchar bigint NOT NULL, chars text, CONSTRAINT pktestdf PRIMARY KEY (numchar) ) WITH ( OIDS=FALSE ); ALTER TABLE testdf OWNER TO postgres; Then in R I create a table with long character variables: > testdf <- data.frame(matrix(NA, 2, 2)) > names(testdf) <- c("numchar&qu...
2008 Feb 26
1
wrapper for save function
...Here is the wrapper for the save function ################################################## wrapsave <- function(mydata, ...) { save(mydata, ...) } ################################################## ## Create a test data.frame and save it ################################################## testdf <- data.frame(a = rnorm(10), b = rnorm(10)) wrapsave(testdf, file = "~/test.Rdata") ################################################## ## remove test data.frame and try to load it ################################################## rm(testdf) load(file = "~/test.Rdata") ##...
2007 Nov 09
2
wrapper for coxph with a subset argument
...sions. I can already achieve my goal, I just would like to know more details about how others do things like this. I've simplified my code below to focus on where I feel I'm confused. Here is some code along with comments: #### BEGIN R SAMPLE CODE #Function for producing test data makeTestDF <- function(n) { times <- sample(1:200, n, replace = TRUE) event <- rbinom(n, 1, prob = .1) trt <- rep(c("A","B"), each = n/2) sex <- factor(c("M","F")) sex <- rep(sex, times = n/2) testdf <- data.frame(times,...
2009 Jun 22
1
Problem with storing a sequence of lmer() model fit into a list
...loop #trouble making line below fit.list[[tmp_i]] <- fit_i I tried the following example which stores glm() model fit without a problem. #the following code can store glm() model fit into a list --------------------------------------------------- x1<-runif(200) x2<-rnorm(200) y<-x1+x2 testdf<-data.frame(y=y, x1=x1, x2=x2) indepvec<-c("x1","x2") fit.list<-NULL fit_1<-glm(y~x1,data=testdf) fit_2<-glm(y~x2,data=testdf) fit.list[[paste('fit_',indepvec[1],sep='')]]<-fit_1 fit.list[[paste('fit_',indepvec[12],sep='')]]<-...
2011 Jan 01
3
Retrieving Factors with Levels Ordered
...S" "Bus" "Some" "Col" "Post" table(feducord) feducord Elem Mid HS Bus Some Col Post 30 90 303 108 236 144 89 # The above is what I want. The frequencies agree with # the codebook # Make a data frame and save it. (I want a text file.) testdf <- data.frame(feducord) str(testdf) 'data.frame': 1001 obs. of 1 variable: $ feducord: Ord.factor w/ 7 levels "Elem"<"Mid"<"HS"<..: 5 6 5 7 3 4 3 3 3 5 ... write.table(testdf, file = 'Junkarea/test.txt') # So far, so good. rm(test...
2009 Feb 20
2
Grouped bwplots?
Dear list, I am sorry for asking you this, but I am trying to do again what I thought I have done before, although this time it does not work. So, given the data set: > testdf <- data.frame(grfak=sample(c("One","Two"),size=100,replace=TRUE), panfak= sample(c("Yes","No"),size=100,replace=TRUE), xfak= sample(c("Yep","Nope"),size=100,replace=TRUE), d=rnorm(100)) I would like to do: > bwplot(d ~ xfak | panf...
2012 Nov 13
0
GAM model to reduce PACF of a model
...I am fitting a gam mode in the mgcv package to study associations of environmental pollutants and mortality. The aim is to choose a model with lowest mgcv and also to reduce the PACF to less than < |0.1|. library(gamair) library(mgcv) data(chicago) y<-matrix(0,12,5) for (i in 1:12) { testdf<-gam(death ~ pm10median + o3median + s(time,k=i*14,fx=T) + s(tmpd,bs="cr"), data=chicago,family=poisson) y[i,1]<-i y[i,2]<-summary(testdf)$p.coeff[2] ll<-summary(testdf)$p.coeff[2]-1.96*summary(testdf)$se[2] ul<-summary(testdf)$p.coeff[2]+1.96*summary...
2007 Dec 19
1
Different labels by panel in barchart
...9;m using lattice to create a plot with each question in a category on it. The problem is that the response set for different questions within the same category varies. I want to be able to draw only the relevant bars, without spaces for nonrelevant reposnes. An example may make it clearer: testdf = data.frame(y=c(23,34,45, 56), x=factor(c("a", "a", "b", "c")), g=factor(c(1,2,1,2))) barchart(y~x|g, data=testdf) #In the first panel I would like two columns "a" and "b", positioned at 1 and 2 respectively; in the second I would agai...
2011 May 17
1
Dealing with null values Aggregate function
...ld like to calculate aggregate values for groups. I am just no sure how to deal with the "" I would ideally like them to ignored ie if there is only 1 value over several columns than that value would be the summary statistic. I have put the following example together to show my problem. testDF <- data.frame(v1 = c(1,3,5,7,8,3,5,NA,4,5,7,9), v2 = c(11,33,55,77,88,33,55,NA,44,55,77,99), v3=c("red","red","red","red","red","red","blue","blue","blue","blue","bl ue...
2007 Feb 20
1
Difficulties with dataframe filter using elements from an array created using a for loop or seq()
...nt(handmadevector) print(loopvector) print(seqvector) ## As a simple testcase, I create a dataframe with two variables, a varA of dummy data, and bBins ## which is the column on which I was trying to filter. a <- c(0,1,2,0,1,3,4,5,3,5) b <- c(0.05,0.15,0.25,0.35,0.45,0.55,0.65,0.75,0.85,0.95) testdf <- data.frame(varA = a, bBins = b) attach(testdf) ## Loop through each of the vectors, create a filter on the dataframe based on equality with the current iteration, ## and print that number and the count of records in the dataframe that match that number. for (i in loopvector){ aqs_filt <- b...
2008 Apr 03
1
by "infelicity"
...iour of the by function. It occurs both under GNU/Linux R 2.6.2 and Windows R 2.7.0alpha. Respective sessionInfo()'s are given below. I hope I do not overlook anything. testFactor <- factor(sample(LETTERS[1:6], size = 42, replace = TRUE)) testMatrix <- matrix(rnorm(42 * 6), nrow = 42) testDf <- as.data.frame(testMatrix) by(data = testDf, INDICES = testFactor, FUN = mean) # OK by(data = testDf, INDICES = testFactor, FUN = median) # error # Error in median.default(data[x, ], ...) : need numeric data Kind regards, Tobias ### GNU/Linux ### > sessionInfo() R version 2.6.2 (2008-02...
2006 Mar 29
1
calcualtign a trailing 12 column mean in a dataframe?
I have a dataframe of 25 columns and 100,000 rows called ?testdf?. I wish to build a new dataframe, with 14 columns and 100,000 rows. I wish the new dataframe to have the ?trailing 12 column? mean. That is, I want column 1 of the new dataframe to have soemthing like: ?( mean(testdf[,1:12],na.rm=T)? What is the best way to accomplish this?
2010 Jul 19
1
pcaMethods and Lattice help.
I've been using the pcaMethods to develop a scores matrix ======================================= data(iris) pcIr <- pca(iris[,1:4], method="nipals", nPcs=3, cv="q2") test <- scores(pcIr) ======================================== What I'm looking to do is to use lattice's barchart to plot the scores something like below, but expanded to all the scores
2013 Oct 07
1
Why read.table replacing space with "." in the header
...???? 3 A.K. Hello Guys Please look at the following code. I dont have "." in the input data frame. But why i am getting when i read the data.frame again. dd <- data.frame("Phylo Tree"= c(1:10), "Genesis Tree"= c(2:11)) ?write.table(dd, "D:\\Write_XML\\testdf.csv", sep=",") ?yy <- read.table("D:\\Write_XML\\testdf.csv", sep=",") ?names(yy) [1] "Phylo.Tree" ? "Genesis.Tree" Thanks Krishna
2011 Jul 01
4
Access only part of last dimension of table/matrix
...tabfn <- function (dfrm, facvec, YN ="event"){ return( Etbl <- do.call(table, dfrm[ , c(facvec, "event") ]) ) # just want Etbl[,,,"TRUE"] or Etbl[,, "TRUE"] or Etbl[,"TRUE"] } tbl <- tabfn(testdf, c("x", "y") ) tbl # all value of event returned At the console it is easy for me to count the number of factors and use the right number of commas tbl[ , , "TRUE"] if I only want the slice with that value. How can I do this programmatically? Thnks. -- Dav...
2011 Jun 05
3
How to convert a factor column into a numeric one?
I have a data frame: > head(df) Time Temp Conc Repl Log10 1 0 -20 H 1 6.406547 2 2 -20 H 1 5.738683 3 7 -20 H 1 5.796394 4 14 -20 H 1 4.413691 5 0 4 H 1 6.406547 7 7 4 H 1 5.705433 > str(df) 'data.frame': 177 obs. of 5 variables: $ Time : Factor w/ 4 levels
2007 Dec 19
3
Aggregating by a grouping
Suppose I have: Book Value A 10 B 11 C 9 D 8 A 12 C 4 D 5 B 7 I want to summarize above not by Book but by groupings of Books as in (below) I have a list ... basic_map <- list(c("A",B"),c("C,D")) Big_names <- c("A1", "A2") Names(basic_map) <- big_names So I want to get : A1 40 A2 26 How do I use tapply AND the list to get my