[R] a new df with one combined column

David L Carlson dcarlson at tamu.edu
Wed Jun 29 16:09:55 CEST 2016


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.



More information about the R-help mailing list