[R] Replace a column value on condition

2015-03-23 Thread Kuma Raj
I want to replace column c3 with values from column c2 whenever values of column Id are 2. In stata I could use replace c3 = c2 if id ==2. How could I do that in R? Thanks Sample data found below: dput(df4) structure(list(c2 = c(42L, 42L, 47L, 47L, 55L, 55L, 36L, 36L, 61L, 61L), c3 = c(68L,

[R] Aggegate minutes data to hourly data

2015-03-11 Thread Kuma Raj
I have a measurement that was taken in 15 minutes or more and want to aggregate it by hour. How could I do that? Sample data is found below date_time concentration 26/11/2013 15:46 529.25 26/11/2013 16:03 1596 26/11/2013 16:23 1027.111 26/11/2013 16:39 1001.9 26/11/2013 16:54 -80.25 26/11/2013

[R] rename columns with pattern

2015-01-12 Thread Kuma Raj
I want to rename columns 1 to 6 in the sample data set as bp_1 to bp_6. How could I do that in R? Thanks dput(dff) structure(list(one = c(1.00027378507871, 0.982313483915127, 1.1531279945243, 1.07400410677618, 1.22710472279261, 1.19762271047046, 1.10904859685147, 1.32060232717317), two =

[R] Create previous dates from date with consideration of leap year

2014-12-11 Thread Kuma Raj
Dear R Community, I wish to create 5 preceding dates from the date variable by ID. How could I create such dates? The code should consider leap year. Thanks Sample data follows: structure(list(id = 1:12, date = structure(c(9L, 6L, 11L, 8L, 7L, 5L, 4L, 3L, 12L, 1L, 10L, 2L), .Label =

[R] How to update R without losing packages

2014-10-31 Thread Kuma Raj
A solution on the link below provides the steps of updating R without losing packages in Unix. http://zvfak.blogspot.se/2012/06/updating-r-but-keeping-your-installed.html How could I do that on windows 7 platform? Thanks __ R-help@r-project.org

[R] How can I merge data with differing length?

2014-10-30 Thread Kuma Raj
How can I merge data frame df and tem shown below by filling the head of tem with missing values? a- rnorm(1825, 20) b- rnorm(1825, 30) date-seq(as.Date(2000/1/1), by = day, length.out = 1825) df-data.frame(date,a,b) tem- rpois(1095, lambda=21) Thanks

[R] How to sum some columns based on their names

2014-10-13 Thread Kuma Raj
I want to sum columns based on their names. As an exampel how could I sum columns which contain 6574, 7584 and 85 as column names? In addition, how could I sum those which contain 6574, 7584 and 85 in ther names and have a prefix f. My data contains several variables with I want to sum columns

[R] Generate sequence of date based on a group ID

2014-10-08 Thread Kuma Raj
I want to generate a sequence of date based on a group id(similar IDs should have same date). The id variable contains unequal observations and the length of the data set also varies. How could I create a sequence that starts on specific date (say January 1, 2000 onwards) and continues until the

[R] How to combine character month and year columns into one column

2014-09-23 Thread Kuma Raj
Dear R users, I have a data with month and year columns which are both characters and wanted to create a new column like Jan-1999 with the following code. The result is all NA for the month part. What is wrong with the and what is the right way to combine the two? ddf$MonthDay -

Re: [R] How to combine character month and year columns into one column

2014-09-23 Thread Kuma Raj
if you could suggest a working solution Thanks On 23 September 2014 18:03, Marc Schwartz marc_schwa...@me.com wrote: On Sep 23, 2014, at 10:41 AM, Kuma Raj pollar...@gmail.com wrote: Dear R users, I have a data with month and year columns which are both characters and wanted to create a new

[R] How to identify outliers with values five times 99th percentile

2014-09-09 Thread Kuma Raj
I have a data frame with some extreme values which I wish to identify and repeat an analysis without these extreme values. How could I identify several columns with values which are 5 times higher than the 99th percentile? Sample data is pasted below. dput(df) structure(list(ad1 = c(98, 6.9,

[R] Obtain coefficients of several nlme objects

2014-09-05 Thread Kuma Raj
I have several lme objects like the ones shown below and I wish to combine the coefficients and confidence intervals of fixed effects of several models. Is there a function that could do that job? m1 - lme(mark1 ~ pm10 + temp + + age + gender + bmi + statin + smoke + dow + season

[R] Subset a column with specific characters

2014-09-04 Thread Kuma Raj
This post has NOT been accepted by the mailing list yet. I would like to subset a column based on the contents of a column with specific character. In the sample data I wish to do the following: First keep the data based on column prog if prog contains ca, and secondly to drop if race contains ic

[R] Loop through columns of outcomes

2013-11-12 Thread Kuma Raj
I have asked this question on SO, but it attracted no response, thus I am cross- posting it here with the hope that someone would help. I want to estimate the effect of pm10 and o3 on three outcome(death, cvd and resp). What I want to do is run one model for each of the main predictors (pm10

Re: [R] Loop through columns of outcomes

2013-11-12 Thread Kuma Raj
') + Lag(%s,0:6), o, v) gam(as.formula(f),family=quasipoisson,na.action=na.omit,data=df) })}) m1 - unlist(m1, recursive = FALSE) m1 Hope this helps, Rui Barradas Em 12-11-2013 09:53, Kuma Raj escreveu: I have asked this question on SO, but it attracted no response, thus I am

Re: [R] Loop through columns of outcomes

2013-11-12 Thread Kuma Raj
, `[[`, 'p.table') Hope this helps, Rui Barradas Em 12-11-2013 13:28, Kuma Raj escreveu: Thanks for the script which works perfectly. I am interested to do model checking and also interested to extract the coefficients for linear and spline terms. For model checkup I could run this script which

[R] Remove a column of a matrix with unnamed column header

2013-11-08 Thread Kuma Raj
I have a matrix names test which I want to convert to a data frame. When I use a command test2-as.data.frame(test) it is executed without a problem. But when I want to browse the content I receive an error message Error in data.frame(outcome = c(cardva, respir, cereb, neoplasm, : duplicate

Re: [R] Remove a column of a matrix with unnamed column header

2013-11-08 Thread Kuma Raj
Hasselman b...@xs4all.nl wrote: On 08-11-2013, at 10:40, Kuma Raj pollar...@gmail.com wrote: I have a matrix names test which I want to convert to a data frame. When I use a command test2-as.data.frame(test) it is executed without a problem. But when I want to browse the content I