|
Hi everyone,
I am having some problems with making a new colomn wit data in it. I have this one column named: Fulfilled Fulfilled 1 1 0 1 1 1 1 0 0 1 And now I would like to add another colum to my .csv file ("Finished") In this "Finished" column I would like to have "Yes" or "No". Where in colomn "Fullfilled" is a 1, "Finished" should have a "Yes". Like this: Fullfilled Finished 1 Yes 1 Yes 0 No etc Now I know how to grab the data out of a column, and also know how to save data inside a .csv file. That is no problem. But how do I get the right Yes or No on the right place in the other column? # Get al values: 1 Fullfilled_1 = Fullfilled[Fullfilled = 1] I was thinkng about subset. But I don' t realy know if that would be realy it.... Maybe somebody here can push me a little in the right direction? |
|
Assuming you actually have a data frame or matrix, and not a csv file, ifelse() is the general solution to your problem.
Sarah On May 14, 2012, at 8:45 AM, Yellow <[hidden email]> wrote: > Hi everyone, > > I am having some problems with making a new colomn wit data in it. > I have this one column named: Fulfilled > > Fulfilled > 1 > 1 > 0 > 1 > 1 > 1 > 1 > 0 > 0 > 1 > > And now I would like to add another colum to my .csv file ("Finished") > > In this "Finished" column I would like to have "Yes" or "No". > Where in colomn "Fullfilled" is a 1, "Finished" should have a "Yes". > Like this: > > Fullfilled Finished > 1 Yes > 1 Yes > 0 No > etc > > Now I know how to grab the data out of a column, and also know how to save > data inside a .csv file. > That is no problem. > But how do I get the right Yes or No on the right place in the other column? > > # Get al values: 1 > Fullfilled_1 = Fullfilled[Fullfilled = 1] > > I was thinkng about subset. > But I don' t realy know if that would be realy it.... > > Maybe somebody here can push me a little in the right direction? > > > -- > View this message in context: http://r.789695.n4.nabble.com/Add-column-from-other-columns-data-tp4629921.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
|
In reply to this post by Yellow
Something along the lines of
dat2 <- ifelse( dat1==1 , "yes", "no") should do it. John Kane Kingston ON Canada > -----Original Message----- > From: [hidden email] > Sent: Mon, 14 May 2012 05:45:38 -0700 (PDT) > To: [hidden email] > Subject: [R] Add column from other columns data. > > Hi everyone, > > I am having some problems with making a new colomn wit data in it. > I have this one column named: Fulfilled > > Fulfilled > 1 > 1 > 0 > 1 > 1 > 1 > 1 > 0 > 0 > 1 > > And now I would like to add another colum to my .csv file ("Finished") > > In this "Finished" column I would like to have "Yes" or "No". > Where in colomn "Fullfilled" is a 1, "Finished" should have a "Yes". > Like this: > > Fullfilled Finished > 1 Yes > 1 Yes > 0 No > etc > > Now I know how to grab the data out of a column, and also know how to > save > data inside a .csv file. > That is no problem. > But how do I get the right Yes or No on the right place in the other > column? > > # Get al values: 1 > Fullfilled_1 = Fullfilled[Fullfilled = 1] > > I was thinkng about subset. > But I don' t realy know if that would be realy it.... > > Maybe somebody here can push me a little in the right direction? > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Add-column-from-other-columns-data-tp4629921.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ____________________________________________________________ Publish your photos in seconds for FREE TRY IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if4 ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
|
In reply to this post by Sarah Goslee
That worked.
Thanks. :) |
|
In reply to this post by John Kane
> Something along the lines of
> > dat2 <- ifelse( dat1==1 , "yes", "no") Another option is in this case dat2 <- c("no", "yes")[dat1+1] Regards Petr > > should do it. > > John Kane > Kingston ON Canada > > > > -----Original Message----- > > From: [hidden email] > > Sent: Mon, 14 May 2012 05:45:38 -0700 (PDT) > > To: [hidden email] > > Subject: [R] Add column from other columns data. > > > > Hi everyone, > > > > I am having some problems with making a new colomn wit data in it. > > I have this one column named: Fulfilled > > > > Fulfilled > > 1 > > 1 > > 0 > > 1 > > 1 > > 1 > > 1 > > 0 > > 0 > > 1 > > > > And now I would like to add another colum to my .csv file ("Finished") > > > > In this "Finished" column I would like to have "Yes" or "No". > > Where in colomn "Fullfilled" is a 1, "Finished" should have a "Yes". > > Like this: > > > > Fullfilled Finished > > 1 Yes > > 1 Yes > > 0 No > > etc > > > > Now I know how to grab the data out of a column, and also know how to > > save > > data inside a .csv file. > > That is no problem. > > But how do I get the right Yes or No on the right place in the other > > column? > > > > # Get al values: 1 > > Fullfilled_1 = Fullfilled[Fullfilled = 1] > > > > I was thinkng about subset. > > But I don' t realy know if that would be realy it.... > > > > Maybe somebody here can push me a little in the right direction? > > > > > > -- > > View this message in context: > > > > Sent from the R help mailing list archive at Nabble.com. > > > > ______________________________________________ > > [hidden email] mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > ____________________________________________________________ > Publish your photos in seconds for FREE > TRY IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if4 > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
| Powered by Nabble | Edit this page |
