[R] How to round only one df row & how to keep 3rd sigdif if zero

2015-06-18 Thread bcrombie
# How do I round only one row of a dataframe? # After transposing a dataframe of counts & rates, all values took on the most # of signif digits in the dataset (rates), but I want counts to remain only one digit. # Also, how can I keep 3 significant digits in R when the 3rd is a zero? count <- c(1,

[R] Make 2nd col of 2-col df into header row of same df then adjust col1 data display

2014-12-17 Thread bcrombie
# I have a dataframe that contains 2 columns: CaseID <- c('1015285', '1005317', '1012281', '1015285', '1015285', '1007183', '1008833', '1015315', '1015322', '1015285') Primary.Viol.Type <- c('AS.Age', 'HS.Hours', 'HS.Hours', 'HS.Hours', 'RK.Records_CL', 'OT.Overtime', 'OT.Overtime', 'OT.Overtime'

Re: [R] Make 2nd col of 2-col df into header row of same df then adjust col1 data display

2014-12-22 Thread bcrombie
Here's the answer to my question that I came up with after working with all of your suggestions. It's not elegant by any means but gets the job done: MERGE_PViol.Detail.Per.Case <- read.csv("~/FOIA_FLSA/MERGE_PViol.Detail.Per.Case_for_rtf10.csv", stringsAsFactors=TRUE) # select only certain colum

[R] create new matrix from user-defined function

2013-07-10 Thread bcrombie
#Let's say I have the following data set: dat3 = data.frame(A_CaseID = c(1881, 1882, 1883, 1884, 1885), B_MW_EEsDue1 = c(2, 2, 1, 4, 6), C_MW_EEsDue2 = c(5, 5, 4, 1, 6), D_MW_EEsDueTotal = c(7, 9, 5, 6, 112)) dat3 # A_CaseID B_MW_EEsDue1 C_MW_E

Re: [R] create new matrix from user-defined function

2013-07-11 Thread bcrombie
2013 5:46 PM To: Crombie, Burnette N Subject: Re: create new matrix from user-defined function > -Original Message- > From: [hidden email] > [mailto:r-help-bounces@r- > project.org<mailto:r-help-bounces@r-%20%0b%3e%20project.org>] On Behalf Of > bcrombie > Sent:

Re: [R] create new matrix from user-defined function

2013-07-12 Thread bcrombie
RS=datTest[addmargins(as.matrix(datTest[,2:3]),2)[,3]!=datTest[,4],1])) # user system elapsed #115.740 0.000 105.778 dtTest<- data.table(datTest) system.time(res3<- subset(dtTest[D!=B+C],select=1)) # user system elapsed # 0.508 0.000 0.477 identical(res1,res2) #[1] TRUE setnames(res3,&qu

Re: [R] create new matrix from user-defined function

2013-07-12 Thread bcrombie
AK, I decided to convert your “with” statement back to index-by-number, and I did look up the ?with help info, but I’m confused about my replacement code below. I got the wrong answer (R didn’t apply the function to my column 1 variable “A_CaseID”). What am I doing wrong? Do I nee

Re: [R] create new matrix from user-defined function

2013-07-15 Thread bcrombie
Arun, thanks for clearing that up. I was making assumptions about R that I shouldn’t have when it comes to column(variable) assignments. Hope everyone has a good Monday. BNC From: arun kirshna [via R] [mailto:ml-node+s789695n4671473...@n4.nabble.com] Sent: Friday, July 12, 2013 11:59 PM To:

[R] combine select data from 2 dataframes sharing same variables

2013-07-17 Thread bcrombie
# The following dataframes are the result of two analyses performed on the same set of numeric data. # The first analysis involved calculations that did not include zero values: StatsUTAH = data.frame(MWtotaleesDue = c(8.428571,2.496256,7,6.604472,1,17,3.593998,4.834573,12.02257),

Re: [R] combine select data from 2 dataframes sharing same variables

2013-07-18 Thread bcrombie
Hi, Peter. Thanks for the suggestion. I will investigate ?merge. BNC From: Peter Alspach-2 [via R] [mailto:ml-node+s789695n4671809...@n4.nabble.com] Sent: Wednesday, July 17, 2013 8:08 PM To: Crombie, Burnette N Subject: Re: combine select data from 2 dataframes sharing same variables Tena koe

Re: [R] combine select data from 2 dataframes sharing same variables

2013-07-18 Thread bcrombie
Wow. That is exactly what I wanted (thread viewers see output below). I think/hope this script will be more user friendly for my needs (RTF final output) than the loop I currently have for LaTex output. Thanks very much A.K. I’ll need to send you a Bundt cake at some point I suppose… BN

[R] condense repetitive code for read.csv and rename.vars

2013-08-14 Thread bcrombie
Is there a more concise way to write the following code? library(gdata) mydataOUTPUTrtfA <- read.csv("mergedStatstA.csv") save(mydataOUTPUTrtfA, file="mydataOUTPUTrtfA.RData") mydataOUTPUTrtfA <- rename.vars(mydataOUTPUTrtfA, from="X", to="Statistics.Calculated", info=FALSE) mydataOUTPUTrtfB <- r

Re: [R] condense repetitive code for read.csv and rename.vars

2013-08-15 Thread bcrombie
les())] sapply(seq_along(vec2),function(i){x1<-read.csv(vec2[i],header=TRUE); colnames(x1)}) # [,1][,2][,3] #[1,] "Statistics.Calculated" "Statistics.Calculated" "Statistics.Calculated" #[2,] "col2"

[R] make stat.desc output an object

2013-05-28 Thread bcrombie
How do I assign a variable to R output that is generated by default functions such as: stat.desc(mydata, basic=TRUE, desc=TRUE, norm=FALSE, p=0.90) summary(mydata) Another way to put it: how can I turn an R function result into an object? -- View this message in context: http://r.789695.n4.n

[R] assigning global columns selection for all subset functions in script

2013-06-11 Thread bcrombie
How do I let R know that I always want to select the same columns in my subset functions (below), so that I don't have to keep copy/pasting the same selection? (thanks) devUni2 <- subset(devUni1, dind02 != 52, select=c(paidhre,earnhre,earnwke,uhourse,hourslw,otc,ind02,dind02,occ00,docc00,lf

Re: [R] assigning global columns selection for all subset functions in script

2013-06-12 Thread bcrombie
Thanks very much, John. This is very helpful. Burnette From: John Kane [via R] [mailto:ml-node+s789695n4669297...@n4.nabble.com] Sent: Tuesday, June 11, 2013 5:35 PM To: Crombie, Burnette N Subject: Re: assigning global columns selection for all subset functions in script index the columns to

Re: [R] assigning global columns selection for all subset functions in script

2013-06-12 Thread bcrombie
o: Crombie, Burnette N Subject: Re: assigning global columns selection for all subset functions in script On Jun 11, 2013, at 9:18 AM, bcrombie wrote: > How do I let R know that I always want to select the same columns in my > subset functions (below), so that I don't have to keep

[R] rewrite script to eliminate constant object reference

2013-06-12 Thread bcrombie
I'm adding a column (region) to a data frame (devUni8), and the (region) column will be populated by a numeric code that is a function of another column (state) in that data frame. See part of the script below. How can I rewrite this so that I could apply the conditions to any data frame without

Re: [R] rewrite script to eliminate constant object reference

2013-06-13 Thread bcrombie
mp;carb==1] <- 2 region[is.na(region)] <- 0 }) ## Here is an alternative using with ## instead of within mtcars$region <- 0 mtcars$region[with(mtcars, gear==4&carb==4)] <- 1 mtcars$region[with(mtcars, gear==3&carb==1)] <- 2 Best, Ista On Wed, Jun 12, 2013 at 4:36 PM,

[R] help with text patterns in strings

2013-06-17 Thread bcrombie
Let’s say I have a data set that includes a column of answers to a question “What days of the week are you most likely to eat steak?”. The answers provided are [1] “Friday”, [2] “Wednesday”, [3] “Friday, Saturday, Sunday", [4] "Saturday”, [5] “Sat, Sun”, [6] “Th, F, Sa” How can I tell R to count “

[R] count and sum simultaneously in R pivot table

2014-02-06 Thread bcrombie
Based on the following code, how can I add a column to this pivot table output that will count CaseID's for each variable sum? CaseID is a factor. # library(reshape) # FLSA_Violation_Reason_melt <- melt(FLSA_ViolRsnfixed, #id=c("CaseID", "ViolationDesc", "Reas

[R] new column that applies function to all rows based on last row

2014-03-03 Thread bcrombie
I know this is a simple question, but I am having trouble generating output without errors. I want to create a column containing values for each row that are generated by dividing another column's row value by the same column's sum (last-row value):

[R] get is.na & !is.na count of various combinations of columns

2014-03-18 Thread bcrombie
I'm trying to count the number of combinations of columns containing data & not containing data as described below. I"m not sure how to do this in R and need some help. #get TRUE/FALSE count of various combinations of columns per CaseID or per Structure mydatatest <- data.frame (CaseID = c("16059

[R] Add column to DF based on 2 columns in another DF

2013-12-10 Thread bcrombie
LookupTable <- read.table(header = TRUE, stringsAsFactors = FALSE, text="Str IND13 IND12 IND11 IND07 IND06 1 517 529 562 562 567 2 517 529 562 562 568 3 517 529

Re: [R] Add column to DF based on 2 columns in another DF

2013-12-10 Thread bcrombie
Thanks, AK. That gets the job done and I learned 2 ways to do it. Much appreciated as always. -- View this message in context: http://r.789695.n4.nabble.com/Add-column-to-DF-based-on-2-columns-in-another-DF-tp4681950p4681969.html Sent from the R help mailing list archive at Nabble.com. ___