[R] a new df with one combined column
PIKAL Petr
petr.pikal at precheza.cz
Thu Jun 30 10:08:09 CEST 2016
Hi.
Hm. As OP has the variables in data frame, I think that the first answer by Ulrik was correct. However different class of those two columns prevents merge to result in one column.
After
df1$License is changed propperly to numeric.
df.merge <- merge(df1, df2, by.x="License", by.y="Diff", all=TRUE)
should result in one merged data frame with combined License/Diff column.
Cheers
Petr
P.S. I noticed that mode and typeof help pages does not have any pointer to class help page, OTOH class help page directs to mode. Maybe link to class could be added to mode help page.
> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of David L
> Carlson
> Sent: Wednesday, June 29, 2016 4:10 PM
> To: Ulrik Stervbo <ulrik.stervbo at gmail.com>; chalabi.elahe at yahoo.de; R-
> help Mailing List <r-help at r-project.org>
> Subject: Re: [R] a new df with one combined column
>
> It looks like License was imported as character data and converted to a factor.
> I'm not sure I understand what you want, but to make them into a single
> column, you need to convert the factor back to numeric using
> as.numeric(as.character(License)), but you use the command levels(License)
> to look at the 384 values in License to be sure there are no non-numeric
> characters, e.g. 41,001. I there are, you will have to remove them.
>
> > set.seed(42)
> > License <- sample(40000:49999, 25)
> > License <- factor(as.character(License))
> > str(License)
> Factor w/ 25 levels "40822","41172",..: 19 21 6 17 12 10 16 3 13 14 ...
> > Diff <- sample(40000:49999, 25)
> > str(Diff)
> int [1:25] 45142 43901 49055 44468 48356 47372 48105 43878 46846 40039 ...
> > Combined <- c(as.numeric(as.character(License)), Diff)
> > str(Combined)
> num [1:50] 49148 49369 42860 48301 46414 ...
> > Combined
> [1] 49148 49369 42860 48301 46414 45188 47361 41345 46564 47044 44572
> 47183 49335 42550 [15] 44616 49386 49766 41172 44741 45592 49022 41384
> 49867 49444 40822 45142 43901 49055 [29] 44468 48356 47372 48105 43878
> 46846 40039 48320 40073 42074 49054 46109 43789 44350 [43] 40373 49717
> 44309 49556 48858 46385 49687 46173
>
>
> -------------------------------------
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77840-4352
>
>
>
>
> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Ulrik
> Stervbo
> Sent: Wednesday, June 29, 2016 8:35 AM
> To: chalabi.elahe at yahoo.de; R-help Mailing List
> Subject: Re: [R] a new df with one combined column
>
> It looks like the function you are searching for is merge()
>
> HTH
> Ulrik
>
> On Wed, 29 Jun 2016 at 15:11 ch.elahe via R-help <r-help at r-project.org>
> wrote:
>
> > Hi all,
> > I have this column as a part of df:
> >
> > $License : Factor W/384 levels
> > "41005","41006","41034","41097","41200",...
> > and I have other column which is a part of other df lets say df2:
> >
> > $Diff : int 41166 41202 41290 41353 41503 41507 41548
> > these two columns df$License and df$Diff have different dimensions and
> > I want to make a new df that is combinations of both i.e. I want a
> > column which has both of these columns together as one column, but I
> > don't know how to bring these two column in one as a new df. Does
> > anyone know how should I do that?
> > Thanks for any help,
> > Elahe
> >
> > ______________________________________________
> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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.
> >
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
________________________________
Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu.
V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá.
This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system.
If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email.
In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.
More information about the R-help
mailing list