[R] conditional value assignment

2012-10-21 Thread penguins
Hi, I am trying to assign values to records based conditionally on other records within a dataframe. For example, in the following dataframe the "NA" value in dat$age would be replaced if the age status for that individual and specific year can be found in another record. Ideally this would then a

Re: [R] conditional value assignment

2012-10-22 Thread penguins
Thanks, that has worked like a dream! -- View this message in context: http://r.789695.n4.nabble.com/conditional-value-assignment-tp4646945p4646988.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list htt

[R] Remove records from a large dataframe

2012-10-22 Thread penguins
Hi, I am trying to remove a series of records from a large dataframe. The script I have written works fine but takes a long time to run. Can anyone suggest a quicker way to do this? Here is an example of the code I've written. The end result of this bit of code would be a dataframe with any record

Re: [R] Remove records from a large dataframe

2012-10-22 Thread penguins
Thanks Rui, your solution works great and is so fast! -- View this message in context: http://r.789695.n4.nabble.com/Remove-records-from-a-large-dataframe-tp4646990p4647029.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-pro

[R] box() doesnt work

2012-10-30 Thread penguins
Hi, when plotting a graphic i find that the surrounding box disappears if I adjust the margins with par(mar=..). Ive tried reassigning it with box() but it doesnt seem to make any difference. Does anyone know a way to overcome this? Thanks in advance -- View this message in context: http://r

[R] conditional increase by increment

2012-07-18 Thread penguins
I am trying to assign increasing trip numbers to a binary variable ("land"; 1=home and 0=away) where a string of 1's shouldn't increment the trip_no more than once. For example; based on land<-c(0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,0) the "trip_no" sequence produced should be 1,1,1,1,2,2,2,2,2,2,3,3,

Re: [R] conditional increase by increment

2012-07-19 Thread penguins
Thanks William, that works fantastically! I had a quick play with my data and have realised a potential problem in that if an individual ends the series at home it records an additional trip-no when one wasnt made. I was wondering whether you could think of a way to alter it slightly so that the i

[R] find date between two other dates

2012-08-05 Thread penguins
Hi, I am trying to assign "Season" values to dates depending on when they occur. For example, the following dates would be assigned the following "Season" numbers based on the "season" intervals detailed below in the code: ddate Season 29/12/1998 20:00:33 1 02

Re: [R] find date between two other dates

2012-08-06 Thread penguins
Thanks arun and Rui; 3 fantastic suggestions. The Season interval is not always a month so arun's suggestion works better for this dataset. I couldn't get the as.between function to work on arun's second suggestion, it only returned NAs. However, arun's first suggestion worked a treat! Many th

[R] map axis on projected shapefiles

2012-08-08 Thread penguins
Hi, I have overlayed 2 projected shapefiles using the "plot" function. When I plot them the numbers next to the x-axis ticks are printed in scientific format (e.g. -4e+05, -3e+05,...,), and the problem is these dont match up to the projected point locations I also wish to overlay from my dataset

Re: [R] map axis on projected shapefiles

2012-08-08 Thread penguins
Since posting this I've figured out the problem was due to the shapefiles I was reading in. As they were already projected they were in meters, as oppose to decimal degrees. By opening the shapefiles in ArcGIS, reprojecting them to WGS1984 and exporting, I could then reload them in R in decimal deg

[R] Remove several numbers from a sequence

2012-08-17 Thread penguins
Can anyone tell me how to remove several numbers for a sequence. For example: xx<- c(1,5,7,10) yy<-seq(1,10,1) how do I get take xx away from yy to get the new sequence 2,3,4,6,8,9 Many thanks in advance -- View this message in context: http://r.789695.n4.nabble.com/Remove-several-numbers-

Re: [R] Remove several numbers from a sequence

2012-08-20 Thread penguins
Hi! Both yy[!(yy %in% xx)] and yy[is.na(match(yy,xx))] work a treat! Developing this topic can anyone tell me how to extract rows which are not replicated across 2 data frames. For example: z1<-c(1,2,3,4) z2<-c(5,6,7,8) zz<- data.frame(cbind(z1,z2)) x1<-c(3,4) x2<-c(7,8) xx<- data.frame(cbind(x

Re: [R] Remove several numbers from a sequence

2012-08-20 Thread penguins
many thanks for lots of different solutions. I have a couple of very large data frames but using the unique identifier for each row and Arun's solution zz[is.na(match(zz$z1,xx$x1)),] has worked perfectly, Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Remove-severa