search for: dframe

Displaying 20 results from an estimated 63 matches for "dframe".

Did you mean: frame
2011 Jun 09
3
How to subset based on column name that is a number ?
Hi, I have a data frame with column names "1", "2", "3", ... and I'd like to extract a subset based on the values in the first column. None of the methods I tried worked (below). x <- subset(dframe, 1 = = "My Text") x <- subset(dframe, "1" = = "My Text") x <- subset(dframe, names(dframe)[1] = = "My Text") Q <- dframe[1 = = "FY11_Q4",] Q <- dframe['1'=="FY11_Q4",] Q <- dframe[names(dframe)[1]=="FY11_Q4&quot...
2008 Nov 25
1
Efficient passing through big data.frame and modifying select
...e merging/duplicate identification of columns > > containing these strings, I wrote the following function, which > > passes through the rows one by one, identifies ";"-containing cells, > > splits and resorts them. > > > > ResortCombinedFields <- function(dframe){ > > if(!is.data.frame(dframe)){ > > stop("\"ResortCombinedFields\" input needs to be a data frame.") > > } > > for(row in seq(nrow(dframe))){ > > for(mef in grep(";",dframe[row,])){ > > I needed to add drop=TRUE to the ab...
2008 Dec 23
1
quotation problem/dataframe names as function input argument.
...wing problem? Many thanks in advance. # Problem Description: # I want to write functions which take a (character) vector of dataframe names as input argument. # For example, I want to extract the number of observations from a number of dataframes. # I tried the following: nobs.fun <- function (dframe.vec) { nobs.vec <- array(NA,c(length(dframe.vec),1)) for (i in 1:length(dframe.vec)) { nobs.vec[i] <- dim(dframe.vec[i])[1] } return(nobs.vec) } # To show the problem, I create a fake dataframe and store its name (i.e., dframe.1) # in a vector (i.e., dframe.vec) of...
2012 Mar 30
1
How to use access results of gregexpr in data frames
Hello, I'm trying to figure out how to find the index of the second occurrence of "/" in a string (which happens to represent a date) within a data frame column. I've used the following code successfully to find the first instance of "/". dframe <- data.frame(date=c("5/14/2011", "4/7/2011")) dframe$x1 <- regexpr("/", dframe[, 1]) dframe date x1 1 5/14/2011 2 2 4/7/2011 2To find the second instance, I thought I'd try to use gregexpr to find all instances of "/" (there's always two pe...
2010 Oct 13
4
Change global env variables from within a function
...global environment in a simple manner. Given: tempdf <- data.frame("a" = 1:6, "b" = 7:12) #I can rename a to g this way: names(tempdf)[names(tempdf)=="a"] <- "g" #Wanting to simplify this for the future, I have the function: colrename <- function(dframe, oldname, newname) { names(dframe)[names(dframe)==oldname] <- newname } colrename(tempdf, "a", "g") #However of course the change to tempdf stays within colrename(). I could add "return(names(dframe))" to the function and then call the function like:...
2004 Dec 12
2
errors when trying to rename data frame columns
Dear R users, I need to rename the columns of a series of data frames. The names of the data frames and those of the columns need to be pulled from some vectors. I tried a couple of things but only got errors. What am I missing? #---create data frame dframes <- c("a","b","c") assign(dframes[2],data.frame(11:20,21:30)) #---rename the columns cols <- c("one","two") > names(get(dframes[2])) <- cols Error: couldn't find function "get<-" > assign(dframes[2],data.frame(cols[...
2006 Jan 20
3
Selecting data frame components by name - do you know a shorter way?
...frame by name, i.e. the input should look like "name1 name2 name3 ..." and the output be a data frame of those components with the corresponding names. I ´ve been trying for hours, but only found the long way to do it (which is not feasible, since I have lots of components to select): dframe[names(dframe)=="name1" | dframe=="name2" | dframe=="name3"] Do you know a shortcut? Michael [[alternative HTML version deleted]]
2005 Nov 09
2
error in NORM lib
...tistics _and_ I checked the manpages and it does not seem that the calls are wrong. Thus, either it depends on the dataset (but why?) or it is maybe a bug. I appreciate every help, thanks, leo g??rtler <---snip---> library(norm) rngseed(1234) load(url("http://www.anicca-vijja.de/lg/dframe.Rdata")) # load object "dframe" dim(dframe) apply(dframe,2,function(x) sum(is.na(x))) # check how many NAs in the dataset #dframe <- subset(dframe,select=-c(alter,grpzugeh,is1,is4,is6,klassenstufe,mmit,vorai,vorap,voras,vorkf,vorsg,vorvb)) s1 <- prelim.norm(dframe) s1$nmis...
2006 Jun 09
3
sqlSave() and rownames=TRUE makes my Rgui crash
...DBI) library(RODBC) chan <- odbcConnect("MySQL51", uid="root", pwd="xxx") first <- sqlQuery(chan, "select * from example") close(chan) First #[1] pk id col1 col2 #<0 rows> (or 0-length row.names) ### This is the table I'm trying to save: dframe <-data.frame(matrix(1:6,2,3)) colnames(dframe)=c("id","col1","col2") dframe # id col1 col2 #1 1 3 5 #2 2 4 6 ### But this makes Rgui crash and close chan <- odbcConnect("MySQL51", uid="root", pwd="xxx") sqlSave(chan...
2011 Jul 08
1
Referencing a vector of data labels in ggplot function
Hi, I really feel I've looked everywhere, although I know this can't be a hard problem. I'd like to be able to call the graph below as a function, but I can't get the function to recognize variables beyond 'dframe'. I've read through many papers on writing functions in R, but I can't get this to work. data <- data.frame('date' = as.Date(rep(c(15101, 15108, 15115, 15122, 15129, 15136, 15143, 15150),4), origin = '1899-12-30'), 'factor'...
1999 Oct 19
2
Summary bug?
Hi, It seems that there's a bug in summary, in the max. output... but max() alone works fine. > hw04.dframe$area ... [41] 1790 1380 1296 2745 798 2306 438649 1481 1559 2450 ... > summary(hw04.dframe) area Min. : 798 1st Qu.: 1349 Median : 1690 Mean : 6962 3rd Qu.: 2306 Max. :438600 ### should read 438649 or, to the point, > summary(hw...
2000 Jun 25
1
renaming columns
...les using the following command: dimname(dataset[[2]][index.of.variable.to.be.renamed]<-new.variable.name If I want to do this inside a function (say something I call RenameCol) what is the best way to communicate the new.variable.name back to the calling frame (e.g.) RenameCol<-function(dframe, index, newname) { #code to make certain there *are* dimnames dimname(dframe[[2]][index]<-newname invisible() return(dframe) } The above code works in both SPlus and R if the call looks like: dframe<-RenameCol(dframe, 3, "a.new.name") Is there a better way to return the new v...
2008 Nov 25
0
Efficient passing through big data.frame and modifying select fields
...,1] [2] "thing;some" In order to enable merging/duplicate identification of columns containing these strings, I wrote the following function, which passes through the rows one by one, identifies ";"-containing cells, splits and resorts them. ResortCombinedFields <- function(dframe){ if(!is.data.frame(dframe)){ stop("\"ResortCombinedFields\" input needs to be a data frame.") } for(row in seq(nrow(dframe))){ for(mef in grep(";",dframe[row,])){ dframe[row,mef] <- paste(sort(unlist(strsplit(dframe[row,mef],";"))),col...
2002 May 17
0
options()$warn==2 and try()
...and here is what happens (question after R session): ################################# Start R session: > library(survival) > ## Here are 2 calls with different pairs of variables, both of which yield warnings: > qq <- FitModels(vnames=c("acd11apcd3p","drpcd8p"),dframe="ALLmth12",survname="fail tm12", censname="failcens") Warning message: Loglik converged before variable 2 ; beta may be infinite. in: fitter(X, Y, strats, offset, init, control, weights = weights, > ## warnings are just warnings when options()$warn=0: > lap...
2008 Sep 12
2
Finding a vector position using names rather than values
...some guidance. I have a data frame, on which I apply a row function. The result looks to me like a vector that retains the old row names. I then sort the vector and subsequently need to be able to identify the rank of certain values by searching for their row names. See this mock example: > dframe <- data.frame("Col1"=c(10,20,30), "Col2"=c(2,4,6), "Col3"=c(5,10,7), row.names=c("R1","R2","R3")) > row_median<-apply(dframe,1,median) > row_median.sorted <- sort(row_median, decreasing=TRUE) > row_median.sorted R2 R3 R1...
2011 Jul 22
2
averaging rows based on string¿?
...to do in R simply/elegantly, but my R - coding skills seem surpassed. This is the thing. Imagine the following data: labs<-c("abcdef","abcgg","tgthefdk","tgtijuel","tgtnjmoi","gbnt","dlift") dat<-c(0.5,0.25,1,2,16,0.250,4) dframe<-data.frame(labs,dat) I would like to average the values in "dat" according to specific string/text in the name of their row names described by "labs". For example, average the values in "dat" if the first three (or more) letters in their corresponding "labs&q...
2010 Jul 09
2
select columns from vector of column names
...am trying to do. Is there a better solution? #names of desired columns colnames <- c("col1","col3") #my data data <- data.frame("col1"=c(1,2,3),"col2"=c("A","B","C"),"col3"=c(4,5,6)) fun <- function(colname,dframe){ nframe <- subset(dframe,select=colname) vec <- nframe[,1] return(vec) } fun(colnames[1],data) fun(colnames[2],data) [[alternative HTML version deleted]]
2004 Apr 22
1
Selection of cities sample
Hi, I have a question, how to most properly select set of cities which would be as similar as possible in some particular variables with the City of Boston (which I use as my base line). I thought about ordering cities by sum of ((differences between value of that particular variable for that particular city and the value of same variable for Boston) divided by the standard deviation of the
2012 Aug 24
1
help with a special variant of balloonplot
Hi, I am interested in implementing a special variant of balloonplot.  Let me explain with an example dataset from the reference manual : library(gplots) data(Titanic) dframe<-as.data.frame(Titanic) survived<-dframe[dframe$Survived=="Yes",] attach(survived) balloonplot(x=Class,y=list(Age,Sex),z=Freq,sort=TRUE,show.zeros=TRUE,cum.margins=FALSE,             main="BalloonPlot : Surviving passengers") # standard plot # Now comes the attempt at some...
2010 Mar 11
3
Define column names to a series of data.frames
...ith assign, get, paste, for but I am not getting anywhere. I need to integrate this in a function that can handle lot's of data.frames and not only 6. Thank you, Nikos --- [1] I am stuck on this post: <http://www.mail-archive.com/r-help at stat.math.ethz.ch/msg32063.html>. It reads: dframes <- c("a","b","c") cols <- c("one","two") df <- data.frame(11:20, 21:30) names(df) <- cols assign(dframes[2], df) Can't understand the logic behind the "[2]".