Re: [R] data manipulation question

2021-08-23 Thread Jim Lemon
Hi Kai, How about setting: germlinepatients$DisclosureStatus <- NA then having your three conditional statements as indices: germlinepatients$DisclosureStatus[germlinepatients$gl_resultsdisclosed == 1] <-"DISCLOSED" germlinepatients$DisclosureStatus[germlinepatients$ gl_resultsdisclosed == 0]

Re: [R] data manipulation

2016-12-19 Thread Duncan Mackay
"data.frame", row.names = c(NA, -396L )) Regards Duncan -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Monday, 19 December 2016 13:47 To: Duncan Mackay Cc: R Subject: Re: [R] data manipulation > On Dec 18, 2016, at 5:39 PM, Duncan Mackay <

Re: [R] data manipulation

2016-12-18 Thread David Winsemius
an >>> Duncan Mackay >>> Department of Agronomy and Soil Science >>> University of New England >>> Armidale NSW 2351 >>> Email: home: mac...@northnet.com.au >>> >>> -Original Message- >>> From: R-help [mailto:r-help-boun

Re: [R] data manipulation

2016-12-18 Thread David Winsemius
Original Message- > From: David Winsemius [mailto:dwinsem...@comcast.net] > Sent: Monday, 19 December 2016 05:36 > To: Duncan Mackay > Cc: R > Subject: Re: [R] data manipulation > > >> On Dec 17, 2016, at 7:57 PM, Duncan Mackay <dulca...@bigpond.com> wrote: >

Re: [R] data manipulation

2016-12-18 Thread Duncan Mackay
Hi David Thanks for the info. As a test I am attaching it anyway Regards Duncan -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Monday, 19 December 2016 05:36 To: Duncan Mackay Cc: R Subject: Re: [R] data manipulation > On Dec 17, 2016, at 7:57

Re: [R] data manipulation

2016-12-18 Thread peter dalgaard
New England >> Armidale NSW 2351 >> Email: home: mac...@northnet.com.au >> >> -----Original Message- >> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rui Barradas >> Sent: Thursday, 15 December 2016 01:19 >> To: Farshad Fathian; r-help

Re: [R] data manipulation

2016-12-18 Thread David Winsemius
> -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rui Barradas > Sent: Thursday, 15 December 2016 01:19 > To: Farshad Fathian; r-help > Subject: Re: [R] data manipulation > > Hello, > > Please cc your mails to the list.

Re: [R] data manipulation

2016-12-18 Thread David Winsemius
ect.org] On Behalf Of Rui Barradas > Sent: Thursday, 15 December 2016 01:19 > To: Farshad Fathian; r-help > Subject: Re: [R] data manipulation > > Hello, > > Please cc your mails to the list. > As for your data, your url is wrong, you need to contact Massey or maybe > the

Re: [R] data manipulation

2016-12-17 Thread Duncan Mackay
of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rui Barradas Sent: Thursday, 15 December 2016 01:19 To: Farshad Fathian; r-help Subject: Re: [R] data

Re: [R] data manipulation

2016-12-15 Thread John Kane via R-help
That should read "now" instead of "not" On Thursday, December 15, 2016 6:49 PM, John Kane wrote: It downloaded a file for me earlier but I am not getting the 404 error and I did not bother to save the download.  Shrug. On Wednesday, December 14, 2016 6:57

Re: [R] data manipulation

2016-12-15 Thread John Kane via R-help
It downloaded a file for me earlier but I am not getting the 404 error and I did not bother to save the download.  Shrug. On Wednesday, December 14, 2016 6:57 AM, John Kane via R-help wrote: xx <- read.csv("http://massey.ac.nz/~pscoperwait/ts/cbe.dat;) gives me

Re: [R] data manipulation

2016-12-14 Thread Rui Barradas
On Behalf Of Rui Barradas Sent: Wednesday, December 14, 2016 6:12 AM To: John Kane; Farshad Fathian; r-h...@stat.math.ethz.ch Subject: Re: [R] data manipulation Hello, What do you mean by "gives me something"? xx <- read.csv("http://massey.ac.nz/~pscoperwait/ts/cbe.dat;) Erro

Re: [R] data manipulation

2016-12-14 Thread David Winsemius
ge Station, TX 77840-4352 > > > > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rui Barradas > Sent: Wednesday, December 14, 2016 6:12 AM > To: John Kane; Farshad Fathian; r-h...@stat.math.ethz.ch > Subject: Re: [R] data manipulati

Re: [R] data manipulation

2016-12-14 Thread David L Carlson
...@stat.math.ethz.ch Subject: Re: [R] data manipulation Hello, What do you mean by "gives me something"? xx <- read.csv("http://massey.ac.nz/~pscoperwait/ts/cbe.dat;) Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") :

Re: [R] data manipulation

2016-12-14 Thread Rui Barradas
Hello, Please cc your mails to the list. As for your data, your url is wrong, you need to contact Massey or maybe the source of your information and get a valid internet address. Without one there's not much we can do. Rui Barradas Em 14-12-2016 12:16, Farshad Fathian escreveu: Hello,

Re: [R] data manipulation

2016-12-14 Thread Rui Barradas
Hello, What do you mean by "gives me something"? xx <- read.csv("http://massey.ac.nz/~pscoperwait/ts/cbe.dat;) Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open URL 'http://massey.ac.nz/~pscoperwait/ts/cbe.dat': HTTP status

Re: [R] data manipulation

2016-12-14 Thread John Kane via R-help
xx <- read.csv("http://massey.ac.nz/~pscoperwait/ts/cbe.dat;) gives me something. Since we have no idea of what you are doing I don't know if the data has downloaded correctly On Tuesday, December 13, 2016 1:38 PM, Farshad Fathian wrote: Hi, I couldn't

Re: [R] data manipulation

2016-12-13 Thread John McKown
On Tue, Dec 13, 2016 at 3:23 AM, Farshad Fathian wrote: > Hi, > > I couldn't access to data file about PSCoperwait by > http://massey.ac.nz/~pscoperwait/ts/cbe.dat. > ​First off, this post is nearly useless. You don't tell us what you tried to do. And you didn't tell

Re: [R] data manipulation

2016-12-13 Thread Rui Barradas
Hello, And what has your question to do with R? Please read the posting guide before posting and when you do, post a question where at least the link is correct. Rui Barradas Em 13-12-2016 09:23, Farshad Fathian escreveu: Hi, I couldn't access to data file about PSCoperwait by

Re: [R] Data manipulation in a data.frame

2014-02-21 Thread ioanna ioannou
)) Thanks in advance, IOanna -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: 21 February 2014 00:19 To: r-help@r-project.org Cc: ioanna ioannou Subject: Re: [R] Data manipulation in a data.frame Also, rownames(which(t(!!A[,-1]),arr.ind=TRUE)) A.K. On Thursday, February 20

Re: [R] Data manipulation in a data.frame

2014-02-21 Thread Bert Gunter
To: r-help@r-project.org Cc: ioanna ioannou Subject: Re: [R] Data manipulation in a data.frame Also, rownames(which(t(!!A[,-1]),arr.ind=TRUE)) A.K. On Thursday, February 20, 2014 6:48 PM, arun smartpink...@yahoo.com wrote: Hi, May be this helps: A$Variable - rep(colnames(A[,-1]),nrow

Re: [R] Data manipulation in a data.frame

2014-02-21 Thread arun
...@yahoo.com] Sent: 21 February 2014 00:19 To: r-help@r-project.org Cc: ioanna ioannou Subject: Re: [R] Data manipulation in a data.frame Also, rownames(which(t(!!A[,-1]),arr.ind=TRUE)) A.K. On Thursday, February 20, 2014 6:48 PM, arun smartpink...@yahoo.com wrote: Hi, May be this helps

Re: [R] Data manipulation in a data.frame

2014-02-21 Thread Bert Gunter
,C,D,none)) Thanks in advance, IOanna -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: 21 February 2014 00:19 To: r-help@r-project.org Cc: ioanna ioannou Subject: Re: [R] Data manipulation in a data.frame Also, rownames(which(t(!!A[,-1]),arr.ind=TRUE)) A.K

Re: [R] Data manipulation in a data.frame

2014-02-21 Thread arun
Hi Ioanna, If you need to paste the colnames if there are multiple 1's per row: You could try: A-data.frame(A=c(10,100,1000,30,50,60,300,3,4,2,20,35,45),B=c(0,1,1,1,0,0,0,0,0,1,0,0,1),C=c(0,0,0,0,1,1,0,0,0,0,1,1,1),D=c(1,0,0,0,0,0,1,0,0,1,NA,1,1)) apply(A[,-1],1,function(x) {x1

Re: [R] Data manipulation in a data.frame

2014-02-20 Thread arun
Hi, May be this helps: A$Variable - rep(colnames(A[,-1]),nrow(A))[t(!!A[,-1])] A.K. On Thursday, February 20, 2014 5:55 PM, ioanna ioannou ii54...@msn.com wrote: Hello, Assuming that I have a data frame A-data.frame(A=c(10,100,1000,30,50,60,300),               B=c(0,1,1,1,0,0,0),       

Re: [R] Data manipulation in a data.frame

2014-02-20 Thread arun
Also, rownames(which(t(!!A[,-1]),arr.ind=TRUE)) A.K. On Thursday, February 20, 2014 6:48 PM, arun smartpink...@yahoo.com wrote: Hi, May be this helps: A$Variable - rep(colnames(A[,-1]),nrow(A))[t(!!A[,-1])] A.K. On Thursday, February 20, 2014 5:55 PM, ioanna ioannou ii54...@msn.com wrote:

Re: [R] Data manipulation in a data.frame

2014-02-20 Thread Bert Gunter
... and yet another approach (written for generalization) names(A)[-1][as.matrix(A[,-1])%*%(seq_len(ncol(A)-1))] [1] D B B B C C D Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly

Re: [R] data manipulation

2013-11-22 Thread Patrick Burns
I think a list is the wrong structure, a vector would be better since you can use 'match': # transform data structure: neutralVec - unlist(neutral_classes) names(neutralVec) - names(neutral_classes[rep(1:length(neutral_classes), sapply(neutral_classes, length))] # get one or more results

Re: [R] data manipulation

2013-11-22 Thread arun
Hi, You could use either: names(which(sapply(lapply(neutral_classes,`%in%`,50),any))) #[1] B #or vec1 -unlist(neutral_classes)  names(vec1) - gsub(\\d+,,names(vec1))  names(vec1)[vec1==50] #[1] B A.K. Hi everyone. I have a list like this: neutral_classes = list(A = 71:100, B = 46:70, C =

Re: [R] data manipulation

2013-11-22 Thread Patrick Burns
The final ) went missing in the command starting 'names(neutralVec) - '. On 22/11/2013 17:51, Patrick Burns wrote: I think a list is the wrong structure, a vector would be better since you can use 'match': # transform data structure: neutralVec - unlist(neutral_classes) names(neutralVec) -

Re: [R] data manipulation

2013-11-22 Thread philippe massicotte
Thank you everyone for your suggestions. Date: Fri, 22 Nov 2013 18:04:16 + From: pbu...@pburns.seanet.com To: pmassico...@hotmail.com; r-help@r-project.org Subject: Re: [R] data manipulation The final ) went missing in the command starting 'names(neutralVec) - '. On 22/11/2013 17

Re: [R] data manipulation

2013-11-22 Thread philippe massicotte
...@hotmail.com To: r-help@r-project.org Date: Fri, 22 Nov 2013 18:17:03 + Subject: Re: [R] data manipulation Thank you everyone for your suggestions. Date: Fri, 22 Nov 2013 18:04:16 + From: pbu...@pburns.seanet.com To: pmassico...@hotmail.com; r-help@r-project.org Subject: Re

Re: [R] data manipulation

2013-11-22 Thread David Carlson
-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of philippe massicotte Sent: Friday, November 22, 2013 12:27 PM To: r-help@r-project.org Subject: Re: [R] data manipulation Hi again. I realized that the example I give is not valid, because the number I'm using is not an integer

Re: [R] Data Manipulation in R

2013-10-21 Thread Anamika Chaudhuri
Hi Arun: Thanks for your help. Seperate files are being created by concatenating the rows from the two files but I was looking to have them as columns rather than text. This is the way it appears in Excel with row # at the beginning. X Y1 Y2 1 1 4 0 20 17 1 20 52 15 18 Ideally I would like it to

Re: [R] Data Manipulation in R

2013-10-21 Thread arun
Hi, I am getting this.  res - lapply(seq_len(nrow(Y1)),function(i) {dat - data.frame(X=i,Y1=unlist(Y1[i,]),Y2=unlist(Y2[i,])); row.names(dat) - 1:nrow(dat); write.csv(dat,paste0(Anam,i,.csv),row.names=FALSE,quote=FALSE)}) dat1 - read.csv(Anam1.csv,header=TRUE)  dat1   X Y1 Y2 1 1  4 20 2

Re: [R] Data Manipulation in R

2013-10-20 Thread arun
Hi, May be this helps: Y1 - read.table(text=V1 V2 V3 V4 1 4 0 20 17 2 4 0 15 17 3 2 0 13 21,sep=,header=TRUE) Y2 - read.table(text=V1 V2 V3 V4 1 20 52 15 18 2 18 54 14 21 3 18 51 13 21,sep=,header=TRUE)  res - lapply(seq_len(nrow(Y1)),function(i) {dat -

Re: [R] data manipulation

2013-05-15 Thread Berend Hasselman
On 15-05-2013, at 08:15, catalin roibu catalinro...@gmail.com wrote: Hello all! I have a problem with my data. My initial data is a list years and months (see below). I want to transpose my data (12 rows (months) and year values as column). I try t(spi3), but the year values do not appear

Re: [R] data manipulation

2013-05-15 Thread Jim Lemon
On 05/15/2013 04:15 PM, catalin roibu wrote: Hello all! I have a problem with my data. My initial data is a list years and months (see below). I want to transpose my data (12 rows (months) and year values as column). I try t(spi3), but the year values do not appear as column names, but as

Re: [R] Data manipulation

2013-03-15 Thread John Kane
What zero values? And are they acutall zeros or are the NA's, that is, missing values? The code looks okay but without some sample data it is difficult to know exactly what you are doing. The easiest way to supply data is to use the dput() function. Example with your file named testfile:

Re: [R] Data manipulation

2013-03-15 Thread Blaser Nello
Is this what you want to do? D2 - expand.grid(Class=unique(D$Class), X=unique(D$X)) D2 - merge(D2, D, all=TRUE) D2$Count[is.na(D2$Count)] - 0 W - aggregate(D2$Count, list(D2$Class, D2$X), sum) W Best, Nello -Original Message- From: r-help-boun...@r-project.org

Re: [R] Data manipulation

2013-03-15 Thread John Kane
:11:48 + To: jrkrid...@inbox.com, r-help@r-project.org Subject: RE: [R] Data manipulation Hello John, I thought I attached the file. So here we go: Class=c(1,1,1,1, 1,1,1,2,2,2,2,2,2,2,3,3, 3,3,3,3, 3,3,3) X=c(0.1,0.1,0.1, 0.1,0.2,0.2,0.2

Re: [R] Data manipulation

2013-03-15 Thread John Kane
Nice. That does look like it. IOANNA? John Kane Kingston ON Canada -Original Message- From: nbla...@ispm.unibe.ch Sent: Fri, 15 Mar 2013 14:27:03 +0100 To: ii54...@msn.com, r-help@r-project.org Subject: Re: [R] Data manipulation Is this what you want to do? D2 - expand.grid

Re: [R] Data manipulation

2013-03-15 Thread IOANNA
Thanks a lot! -Original Message- From: John Kane [mailto:jrkrid...@inbox.com] Sent: 15 March 2013 13:41 To: Blaser Nello; IOANNA; r-help@r-project.org Subject: Re: [R] Data manipulation Nice. That does look like it. IOANNA? John Kane Kingston ON Canada -Original Message

Re: [R] Data manipulation

2013-03-15 Thread IOANNA
its clearer now. Ioanna -Original Message- From: John Kane [mailto:jrkrid...@inbox.com] Sent: 15 March 2013 12:51 To: IOANNA; r-help@r-project.org Subject: RE: [R] Data manipulation What zero values? And are they acutall zeros or are the NA's, that is, missing values? The code looks

Re: [R] Data manipulation

2013-03-15 Thread David L Carlson
@r- project.org] On Behalf Of IOANNA Sent: Friday, March 15, 2013 8:51 AM To: 'John Kane'; 'Blaser Nello'; r-help@r-project.org Subject: Re: [R] Data manipulation Thanks a lot! -Original Message- From: John Kane [mailto:jrkrid...@inbox.com] Sent: 15 March 2013 13:41 To: Blaser

Re: [R] Data manipulation

2013-03-15 Thread David L Carlson
'; 'Blaser Nello'; r-help@r-project.org Subject: Re: [R] Data manipulation Wouldn't this do the same thing? xtabs(Count~Class+X, D) -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352

Re: [R] data manipulation between vector and matrix

2012-12-05 Thread C W
The only solution I found was x-t(mu) Is there a better way? Mike On Wed, Dec 5, 2012 at 1:30 PM, C W tmrs...@gmail.com wrote: Dear list, I was curious how to subtract a vector from matrix? Say, I have mat - matrix(1:40, nrow=20, ncol=2) x -c(1,2) I want, x-mat[1,] and x-mat[2,],

Re: [R] data manipulation between vector and matrix

2012-12-05 Thread Sarah Goslee
Hi, On Wed, Dec 5, 2012 at 1:30 PM, C W tmrs...@gmail.com wrote: Dear list, I was curious how to subtract a vector from matrix? Say, I have mat - matrix(1:40, nrow=20, ncol=2) x -c(1,2) Thanks for the actual reproducible example. I want, x-mat[1,] and x-mat[2,], and so on...

Re: [R] data manipulation between vector and matrix

2012-12-05 Thread C W
Thanks, Sarah. First time heard about sweep(), it worked just the way I wanted. Mike On Wed, Dec 5, 2012 at 1:42 PM, Sarah Goslee sarah.gos...@gmail.com wrote: Hi, On Wed, Dec 5, 2012 at 1:30 PM, C W tmrs...@gmail.com wrote: Dear list, I was curious how to subtract a vector from matrix?

Re: [R] data manipulation between vector and matrix

2012-12-05 Thread C W
. - Original Message - From: C W tmrs...@gmail.com To: Sarah Goslee sarah.gos...@gmail.com Cc: r-help r-help@r-project.org Sent: Wednesday, December 5, 2012 1:51 PM Subject: Re: [R] data manipulation between vector and matrix Thanks, Sarah. First time heard about sweep(), it worked just

Re: [R] data manipulation between vector and matrix

2012-12-05 Thread arun
: [R] data manipulation between vector and matrix Thanks, Sarah.  First time heard about sweep(), it worked just the way I wanted. Mike On Wed, Dec 5, 2012 at 1:42 PM, Sarah Goslee sarah.gos...@gmail.com wrote: Hi, On Wed, Dec 5, 2012 at 1:30 PM, C W tmrs...@gmail.com wrote: Dear list, I

Re: [R] data manipulation between vector and matrix

2012-12-05 Thread C W
To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org; Sarah Goslee sarah.gos...@gmail.com Sent: Wednesday, December 5, 2012 4:11 PM Subject: Re: [R] data manipulation between vector and matrix thanks, I knew about apply, but did not you you can put plus signs with quotes. That's a cool

Re: [R] data manipulation between vector and matrix

2012-12-05 Thread arun
A.K. From: C W tmrs...@gmail.com To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org; Sarah Goslee sarah.gos...@gmail.com Sent: Wednesday, December 5, 2012 4:11 PM Subject: Re: [R] data manipulation between vector and matrix thanks, I knew

Re: [R] data manipulation between vector and matrix

2012-12-05 Thread arun
: Re: [R] data manipulation between vector and matrix Hi Arun, Sorry, I might be a little unclear with my words. The dimensions are different. This is what I got: x-t(mat)      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [1,]    0   -1   -2   -3   -4   -5   -6   -7

Re: [R] Data manipulation with aggregate

2012-07-04 Thread arun
Hi, Try this: myData = data.frame(Name = c('a', 'a', 'b', 'b'), length = c(1,2,3,4), type= c('x','x','y','z')) z-aggregate(length~Name,myData,mean) z1-aggregate(length~type,myData,mean) merge(z,merge(z,z1),all=TRUE)   Name length type 1    a    1.5    x 2    b    3.5 NA A.K. - Original

Re: [R] Data manipulation with aggregate

2012-07-03 Thread jim holtman
try this: myData = data.frame(Name = c('a', 'a', 'b', 'b'), length = c(1,2,3,4), type + = c('x','x','y','z')) result - do.call(rbind, lapply(split(myData, myData$Name), function(.name){ + data.frame(Name = .name$Name[1L] + , length = mean(.name$length) + , type = if (all(.name$type[1L] ==

Re: [R] Data Manipulation - make diagonal matrix of each element of a matrix

2011-12-16 Thread Clemontina Alexander
Thank you, that is much simpler! On Thu, Dec 15, 2011 at 2:04 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, I believe I can help, or at least, my code is simpler. First, look at your first line: idd - length(diag(1,tt))   # length of intercept matrix # not needed: diag(tt) would

Re: [R] Data Manipulation - make diagonal matrix of each element of a matrix

2011-12-15 Thread Clemontina Alexander
I'm sorry, the indices of my X matrix are wrong. It should be: X = x11 0 0 x12 0 0 0 x11 00 x12 0 0 0 x110 0 x12 x21 0 0 x22 0 0 0 x21 0

Re: [R] Data Manipulation - make diagonal matrix of each element of a matrix

2011-12-15 Thread Rui Barradas
Hello, I believe I can help, or at least, my code is simpler. First, look at your first line: idd - length(diag(1,tt)) # length of intercept matrix # not needed: diag(tt) would do the job but it's not needed, why call 2 functions, and one of them, 'diag', uses memory(*), if the result

Re: [R] data manipulation and summaries with few million rows

2011-08-27 Thread jim holtman
Factors are you friend here: myData mydate gender mygroup id mygrp.f 1 2012-03-25 F A 1 1 2 2005-05-23 F B 2 2 3 2005-09-08 F B 2 2 4 2005-12-07 F B 2 2 5 2006-02-26 F C 2 3 6 2006-05-13 F

Re: [R] data manipulation and summaries with few million rows

2011-08-24 Thread Dennis Murphy
Hi Juliet: Here's a Q D solution: # (1) plyr f - function(d) length(unique(d$mygroup)) - 1 ddply(myData, .(id), f) id V1 1 1 0 2 2 2 3 3 1 4 4 0 # (2) data.table myDT - data.table(myData, key = 'id') myDT[, list(nswitch = length(unique(mygroup)) - 1), by = 'id'] If one can switch

Re: [R] data manipulation and summaries with few million rows

2011-08-24 Thread Juliet Hannah
Thanks Dennis! I'll check this out. Just to clarify, I need the total number of switches/changes regardless of if that state had occurred in the past. So A-A-B-A, would have 2 changes: A to B and B to A. Thanks again. On Wed, Aug 24, 2011 at 1:28 PM, Dennis Murphy djmu...@gmail.com wrote: Hi

Re: [R] Data manipulation

2011-02-12 Thread Johannes Huesing
mathijsdevaan mathijsdev...@gmail.com [Sat, Feb 12, 2011 at 03:00:18PM CET]: Hi, I have a dataset with info on individuals (B) that have been involved in projects (A) during multiple years (C). The dataset contains three columns: A, B, C. Example: A B C 1 1 a 1999 2 1 b 1999 3

Re: [R] Data manipulation

2011-02-12 Thread jim holtman
Will this do it for you: x - read.table(textConnection( A B C + 1 1 a 1999 + 2 1 b 1999 + 3 1 c 1999 + 4 2 c 2001 + 5 2 d 2001 + 6 3 a 2004 + 7 3 b 2004), header = TRUE) closeAllConnections() # add a tenure column x$tenure - ave(x$C, x$B, FUN = function(yr) yr - min(yr)) x

Re: [R] Data manipulation

2011-02-12 Thread mathijsdevaan
That worked great! Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Data-manipulation-tp3302717p3303001.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list

Re: [R] Data manipulation in R

2010-09-24 Thread Dennis Murphy
Hi: Please provide a minimal reproducible example that resembles your real data so that people can try it out and provide potential solutions for you. Show what you tried that failed, and what you expect. A number of people on this list are very adept in data summarization, but most of them are

Re: [R] Data Manipulation

2010-09-10 Thread Joshua Wiley
Hi, Look at the table() function. Here is an example with your data: dat - read.table(textConnection( Study A A B B B A C C D), header = TRUE) closeAllConnections() table(dat) Hope that helps, Josh On Fri, Sep 10, 2010 at 8:53 AM, dfong df...@medicine.umaryland.edu wrote: Hi, I just

Re: [R] Data Manipulation

2010-09-10 Thread dfong
I'm actually importing it from a CSV, so I already have that in a table. But i Can't make a graph with text. I assume I need to do some counting in order to draw the graph? Any example of this? thanks -- View this message in context:

Re: [R] Data Manipulation

2010-09-10 Thread Joshua Wiley
Hi, Yes, the table() function is not to read the data, but to do the frequency counts of each level. I just included the read.table() part so that you could copy and paste my code, but I did not include the R output from table(dat). table(dat) dat A B C D 3 3 2 1 It nicely tallies for you.

Re: [R] Data Manipulation

2010-09-10 Thread Erik Iverson
Hello, This is definitely possible with R, there a lots of package to make good graphics. However, the easiest way for us to help you is if you give us a small reproducible example, as you started to with your initial post. If you have an object in your R session that you'd like help with you

Re: [R] Data manipulation search

2010-08-11 Thread Erik Iverson
?match, look at the %in% operator. Mestat wrote: Hi listers, I made some search, but i didn`t find in the forum. I have a data set. I would like to make a search (conditon) on my data set. x-c(1,2,3,4,5,6,7,8,9,10) count-0 if (CONDITON){count-1}else{count-0} My CONDITION would be: is there

Re: [R] Data manipulation problem

2010-04-09 Thread moleps
In the end after going at it from scratch...This worked out allright... ##set up data age.cat-seq(0,100,10) year-(1953:(1953+55)) dat.vec-sample(1:10,(length(age.cat)*length(year))) dat.matrix-matrix(dat.vec,c(length(age.cat),length(year))) rownames(dat.matrix)-age.cat

Re: [R] Data manipulation problem

2010-04-09 Thread Dieter Menne
Bert Gunter wrote: Yes. Don't do this. (what you probably really want to do is fit a model with age as a factor, which can be done statistically e.g. by logistic regression; or graphically using conditioning plots, e.g. via trellis graphics (the lattice package). This avoids the

Re: [R] Data manipulation problem

2010-04-07 Thread moleps islon
So.. here we try again. ##generate dataset age.cat-seq(0,100,10) year-(1953:(1953+55)) data.vec-sample(1:1,(age.cat*year)) data.matrix-matrix(data.vec,c(length(age.cat),length(year)) rownames(data.matrix)-age.cat colnames(data.matrix)-year ##divide into 5 year periods

Re: [R] Data manipulation problem

2010-04-07 Thread David Winsemius
That code throws multiple errors. Can you at least test your code before posting? (And, again, please avoid using function names as names for your objects.) -- David. On Apr 7, 2010, at 8:54 AM, moleps islon wrote: So.. here we try again. ##generate dataset age.cat-seq(0,100,10)

Re: [R] Data manipulation problem

2010-04-06 Thread moleps islon
OK... next question.. Which is still a data manipulation problem so I believe the heading is still OK. ##So now I read my population data from excel. pop-read.csv(pop.csv) typeof(pop) ## yields a list where I have age-specific population rows and a yearly column population, where the years are

Re: [R] Data manipulation problem

2010-04-06 Thread David Winsemius
On Apr 6, 2010, at 9:56 AM, moleps islon wrote: OK... next question.. Which is still a data manipulation problem so I believe the heading is still OK. ##So now I read my population data from excel. No, you read it from a text file and providing the first ten lines of that text file should

Re: [R] Data manipulation problem

2010-04-06 Thread David Winsemius
On Apr 6, 2010, at 3:30 PM, David Winsemius wrote: On Apr 6, 2010, at 9:56 AM, moleps islon wrote: OK... next question.. Which is still a data manipulation problem so I believe the heading is still OK. ##So now I read my population data from excel. No, you read it from a text file and

Re: [R] Data manipulation problem

2010-04-05 Thread Erik Iverson
?cut to create categories ?table to make the table moleps wrote: Dear R´ers. I´ve got a dataset with age and year of diagnosis. In order to age-standardize the incidence I need to transform the data into a matrix with age-groups (divided in 5 or 10 years) along one axis and year divided into 5

Re: [R] Data manipulation problem

2010-04-05 Thread Bert Gunter
You have tempted, and being weak, I yield to temptation: Any good ideas? Yes. Don't do this. (what you probably really want to do is fit a model with age as a factor, which can be done statistically e.g. by logistic regression; or graphically using conditioning plots, e.g. via trellis graphics

Re: [R] Data manipulation problem

2010-04-05 Thread moleps
I already did try the regression modeling approach. However the epidemiologists (referee) turns out to be quite fond of comparing the incidence rates to different standard populations, hence the need for this labourius approach. And trying the cutting approach I ended up with : table (age5)

Re: [R] Data manipulation problem

2010-04-05 Thread Erik Iverson
I don't know what your data are like, since you haven't given a reproducible example. I was imagining something like: ## generate fake data age - sample(20:90, 100, replace = TRUE) year - sample(1950:2000, 100, replace = TRUE) ##look at big table table(age, year) ## categorize data ## see

Re: [R] Data manipulation problem

2010-04-05 Thread moleps
Thx Erik, I have no idea what went wrong with the other code snippet, but this one works.. Appreciate it. qta- table(cut(age,breaks = seq(0, 100, by = 10),include.lowest = TRUE),cut(year,breaks=seq(1950,2010,by=5),include.lowest=TRUE)) M On 5. apr. 2010, at 21.45, Erik Iverson wrote: I

Re: [R] Data Manipulation

2010-01-26 Thread Peter Rote
I still struggling with this: error massage: by(AlexETF,AlexETF$Industry,function(a) {filename = paste(C:/ab/,gsub( ,,a$Industry[1]),.txt,sep=) + print(filename) + write.table(a[,3,drop=FALSE],quote=FALSE,col.names=FALSE,row.names=FALSE) + } + ) [1]

Re: [R] Data Manipulation

2010-01-26 Thread Peter Dalgaard
Peter Rote wrote: I still struggling with this: error massage: by(AlexETF,AlexETF$Industry,function(a) {filename = paste(C:/ab/,gsub( ,,a$Industry[1]),.txt,sep=) + print(filename) + write.table(a[,3,drop=FALSE],quote=FALSE,col.names=FALSE,row.names=FALSE) + } + )

Re: [R] Data Manipulation

2010-01-26 Thread Jim Lemon
On 01/26/2010 09:15 PM, Peter Rote wrote: I still struggling with this: error massage: by(AlexETF,AlexETF$Industry,function(a) {filename = paste(C:/ab/,gsub( ,,a$Industry[1]),.txt,sep=) + print(filename) + write.table(a[,3,drop=FALSE],quote=FALSE,col.names=FALSE,row.names=FALSE)

Re: [R] Data Manipulation

2010-01-22 Thread Don MacQueen
Does this example help? a - matrix(letters[1:12], ncol=3) a [,1] [,2] [,3] [1,] a e i [2,] b f j [3,] c g k [4,] d h l write.table(a[,3,drop=FALSE],quote=FALSE,col.names=FALSE,row.names=FALSE) i j k l At 4:11 PM -0800 1/21/10, Peter Rote wrote: Thank you Dieter and

Re: [R] Data Manipulation

2010-01-22 Thread Peter Rote
Thank you Don for the code, but I get the following error massage: by(AlexETF,AlexETF$Industry,function(a) {filename = paste(C:/ab/,gsub( ,,a$Industry[1]),.txt,sep=) + print(filename) + write.table(a[,3,drop=FALSE],quote=FALSE,col.names=FALSE,row.names=FALSE) + } + )

Re: [R] Data Manipulation

2010-01-21 Thread Peter Rote
Thank you Dieter and Rolf, I have solved the slash Problem, but I still struggling with the output files. I have tried this by(AlexETF,AlexETF$Industry,function(a) {filename = paste(C:/ab/,gsub( ,,a$Industry[1]),.txt,sep=) print(filename) write.table(a,file=filename,col.names

Re: [R] Data Manipulation

2010-01-20 Thread Dieter Menne
Peter Rote wrote: I would like to to group the Ticker by Industry and create file names from the Industry Factor and export to a txt file. I have tried the folowing ind=finvizAllexETF$Industry ind is then Aluminum Business Services Regional Airlines ind2=gsub(

Re: [R] Data Manipulation

2010-01-20 Thread Peter Rote
Thank you Dieter, but i still have a problem to write to file. The problem is the slash in file names (Aerospace/Defense Products Services ). If i want it to C:/ab/ so C:/ab/AdvertisingAgencies.txt is ok but C:/ab/Aerospace/Defense-MajorDiversified.txt is not head(AlexETF)

Re: [R] Data Manipulation

2010-01-20 Thread Peter Rote
by the way how do i change the output 1016 Advertising Agencies CMM 1803 Advertising Agencies FMCN 2427 Advertising Agencies IPG 3093 Advertising Agencies MWW 3372 Advertising Agencies OMC 4809 Advertising Agencies VCLK 4832 Advertising Agencies VISN 5005 Advertising Agencies WPPGY 5089

Re: [R] Data Manipulation

2010-01-20 Thread Rolf Turner
A name such as ``Aerospace/Defense etc.'' is certainly not a legal file name under unix-alike systems, and I suspect it would not be even under Windoze. Even if it is, you shouldn't use it! Change the name to ``Aerospace-Defense Products Services'' or something like that, for goodness sake.

Re: [R] Data Manipulation

2010-01-20 Thread Dieter Menne
Peter Rote wrote: but i still have a problem to write to file. The problem is the slash in file names (Aerospace/Defense Products Services ). If i want it to C:/ab/ so C:/ab/AdvertisingAgencies.txt is ok but C:/ab/Aerospace/Defense-MajorDiversified.txt is not As Rolf said, the

Re: [R] data manipulation/subsetting and relation matrix

2009-12-08 Thread jim holtman
try this: myDat - read.table(textConnection(group id 1 101 1 201 1 301 2 401 2 501 2 601 3 701 3 801 3 901),header=TRUE) closeAllConnections() corr_mat -as.matrix(read.table(textConnection(1 1 .5 0 0 0 0 0 0 0 2 .5 1 0 0 0 0 0 0 0 3 00 1.0 0 0 0 0 0 0

Re: [R] Data Manipulation Question

2009-12-04 Thread Barry Rowlingson
On Thu, Dec 3, 2009 at 9:52 PM, John Filben johnfil...@yahoo.com wrote: Can R support data manipulation programming that is available in the SAS datastep?  Specifically, can R support the following: -  Read multiple dataset one record at a time and compare values from each; then base

Re: [R] Data Manipulation Question

2009-12-04 Thread Gray Calhoun
This is probably far more discussion than the question warranted, but... On Thu, Dec 3, 2009 at 11:14 PM, David Winsemius dwinsem...@comcast.net wrote: On Dec 3, 2009, at 10:52 PM, Gray Calhoun wrote: The data import/export manual can elaborate on a lot of these; this is all straightforward,

Re: [R] data manipulation

2009-12-03 Thread jim holtman
try this: x - c('v2FfaPre15','v2FfaPre10','v2FfaPre5','v2Ffa2', 'v2Ffa3','v2Ffa4') sub(^.*?([0-9]+)$, \\1, x, perl=TRUE) [1] 15 10 5 2 3 4 On Thu, Dec 3, 2009 at 9:00 AM, oscar linares wins...@gmail.com wrote: Dear Wiza[R]ds, I have a data.frame header that looks

Re: [R] data manipulation

2009-12-03 Thread Henrique Dallazuanna
Try this: gsub(.*[^0-9], , header) On Thu, Dec 3, 2009 at 12:00 PM, oscar linares wins...@gmail.com wrote: Dear Wiza[R]ds, I have a data.frame header that looks like this: v2FfaPre15    v2FfaPre10    v2FfaPre5    v2Ffa2    v2Ffa3    v2Ffa4 I need it to look like this, 15    10    5    

Re: [R] data manipulation

2009-12-03 Thread Gabor Grothendieck
Try this where [0-9]+ matches one or more digits and $ matches the end of string. See http://gsubfn.googlecode.com for more. library(gsubfn) x - c(v2FfaPre15, v2FfaPre10, v2FfaPre5, v2Ffa2, v2Ffa3, v2Ffa4) strapply(x, [0-9]+$, c, simplify = TRUE) # or if you want a numeric result: strapply(x,

  1   2   >