search for: ordered_result

Displaying 12 results from an estimated 12 matches for "ordered_result".

2012 Mar 06
1
How to eliminate for next loops in this script
...,"TRVLCMIN")] hh.wt <- hh[c("HOUSEID","WTHHFIN","HHSIZE","HHVEHCNT","HOMETYPE")] hh.wt$HHBIN <- with(hh.wt,{ cut(HHSIZE, breaks=c(0,1,2,3,4,max(HHSIZE)),labels=c("1","2","3","4","5+"),ordered_result=TRUE)}) hh.wt$VEHBIN <- with(hh.wt,{ cut(HHVEHCNT, breaks=c(-1,0,1,2,max(HHVEHCNT)),labels=c("0","1","2","3+"),ordered_result=TRUE)}) hh.wt$DUTYPE <- factor(hh.wt$HOMETYPE, exclude=c("-7","-8","-9")) levels(hh.wt$DUTYPE) &l...
2023 Oct 16
1
Create new data frame with conditional sums
...otpop = c(4000,3500,4500,4100,3900,4250,5100,4700,4950,4800)) # Define the cutoffs # - allow for duplicate entries; by = 0.03; # by = 0.01; cutoffs <- seq(0, 0.20, by = by) # Create a new column with cutoffs dummyData$Cutoff <- cut(dummyData$Pct, breaks = cutoffs, ?? ?labels = cutoffs[-1], ordered_result = TRUE) # Sort data # - we could actually order only the columns: #?? Totpop & Cutoff; dummyData = dummyData[order(dummyData$Cutoff), ] # Result cs = cumsum(dummyData$Totpop) # Only last entry: # - I do not have a nice one-liner, but this should do it: isLast = rev(! duplicated(rev(dummyData...
2023 Oct 16
1
Create new data frame with conditional sums
...0,4700,4950,4800)) > > # Define the cutoffs > # - allow for duplicate entries; > by = 0.03; # by = 0.01; > cutoffs <- seq(0, 0.20, by = by) > > # Create a new column with cutoffs > dummyData$Cutoff <- cut(dummyData$Pct, breaks = cutoffs, > labels = cutoffs[-1], ordered_result = TRUE) > > # Sort data > # - we could actually order only the columns: > # Totpop & Cutoff; > dummyData = dummyData[order(dummyData$Cutoff), ] > > # Result > cs = cumsum(dummyData$Totpop) > > # Only last entry: > # - I do not have a nice one-liner, but this s...
2023 Oct 15
1
Create new data frame with conditional sums
Dear Jason, I do not think that the solution based on aggregate offered by GPT was correct. That quasi-solution only aggregates for every individual level. As I understand, you want the cumulative sum. The idea was proposed by Bert; you need only to sort first based on the cutoff (e.g. using an ordered factor). And then only extract the last value for each level. If Pct is unique, than you
2008 Jan 30
1
"hist" combines two lowest categories -- is there a workaround?
When preparing a series of histograms I found that hist was combining the two lowest categories or bins, 1 and 2. Specifying breaks, as illustrated below, resulted in the correct histogram: values <- sample(10,500,replace=TRUE) hist(values) hist(values,breaks = 0:10) Apparently, the number of values strictly less than 1 is shown in the first bin (and since none is less than 1,
2011 Jan 27
2
creating categorical frequency tables from continuous data
Hello, I am working with a dataset which essentially has only one column - a list of distances in metres, accurate to several decimal places. eg distance 1000 6403.124 1000 1414.214 1414.214 1000 I want to organise this into a frequency table, grouping into categories of 0 - 999, 1000 - 1999, 2000-2999 etc. I'd also like the rows where there are no data points in that category to
2017 Jun 04
0
New var
...DFM$end, format="%m/%d/%Y" ) DFM$D <- as.numeric( DFM$end - DFM$start, units="days" ) # categorize your data into groups DFM$bin <- cut( DFM$D , breaks=c( seq( 0, 500, 100 ), Inf ) , right=FALSE # do not include the right edge , ordered_result = TRUE ) # brute force method you should have been able to figure out to show us some work DFM$t1 <- ifelse( DFM$D < 100, 1, 0 ) DFM$t2 <- ifelse( 100 <= DFM$D & DFM$D < 200, 1, ifelse( DFM$D < 100, -1, 0 ) ) DFM$t3 <- ifelse( 200 <= DFM$D & DFM$D <...
2017 Jun 04
2
New var
.../%Y" ) > DFM$D <- as.numeric( DFM$end - DFM$start, units="days" ) > # categorize your data into groups > DFM$bin <- cut( DFM$D > , breaks=c( seq( 0, 500, 100 ), Inf ) > , right=FALSE # do not include the right edge > , ordered_result = TRUE > ) > # brute force method you should have been able to figure out to show us > some work > DFM$t1 <- ifelse( DFM$D < 100, 1, 0 ) > DFM$t2 <- ifelse( 100 <= DFM$D & DFM$D < 200, 1, ifelse( DFM$D < 100, -1, > 0 ) ) > DFM$t3 <- ifelse...
2017 Jun 03
2
New var
Thank you all for the useful suggestion. I did some of my homework. library(data.table) DFM <- read.table(header=TRUE, text='obs start end 1 2/1/2015 1/1/2017 2 4/11/2010 1/1/2011 3 1/4/2006 5/3/2007 4 10/1/2007 1/1/2008 5 6/1/2011 1/1/2012 6 10/5/2004 12/1/2004',stringsAsFactors = FALSE) DFM DFM$D =as.numeric(difftime(as.Date(DFM$end,format="%m/%d/%Y"),
2017 Jun 04
0
New var
.../%Y" ) > DFM$D <- as.numeric( DFM$end - DFM$start, units="days" ) > # categorize your data into groups > DFM$bin <- cut( DFM$D > , breaks=c( seq( 0, 500, 100 ), Inf ) > , right=FALSE # do not include the right edge > , ordered_result = TRUE > ) > # brute force method you should have been able to figure out to show us > some work > DFM$t1 <- ifelse( DFM$D < 100, 1, 0 ) > DFM$t2 <- ifelse( 100 <= DFM$D & DFM$D < 200, 1, ifelse( DFM$D < 100, -1, > 0 ) ) > DFM$t3 <- ifelse...
2007 Apr 24
0
R 2.5.0 is released
...dArgs() has a new 'trailingOnly' argument to be used in conjunction with --args. o contour() now passes graphical parameters in '...' to axis() and box(). o New data set 'crimtab' on Student(1908)'s 3000 criminals. o cut.default() has a new argument 'ordered_result'. o .deparseOpts() has two new options: "keepNA" to ensure that different types (logical, integer, double, character and complex) of NAs are distinguished, and "S_compatible" to suppress the use of R-specific features such as 123L and to deparse integer values of a...
2007 Apr 24
0
R 2.5.0 is released
...dArgs() has a new 'trailingOnly' argument to be used in conjunction with --args. o contour() now passes graphical parameters in '...' to axis() and box(). o New data set 'crimtab' on Student(1908)'s 3000 criminals. o cut.default() has a new argument 'ordered_result'. o .deparseOpts() has two new options: "keepNA" to ensure that different types (logical, integer, double, character and complex) of NAs are distinguished, and "S_compatible" to suppress the use of R-specific features such as 123L and to deparse integer values of a...