Charles Berry ucsd.edu> writes:
[snip]
>
> Katherine Gobin yahoo.com> writes:
> > How to automatically identify and retain only one column (in this example
> column x) among the identical
> > columns besides other non-identical columns (viz. id, y and z).
>
> See
>
> ?unique
>
> Details
>
Yes, but the elephant in the room is:
Define: "Identical."
If you do not know why this is an elephant, see FAQ 7.31.
-- Bert
On Thu, Mar 28, 2013 at 8:40 AM, Charles Berry wrote:
> Katherine Gobin yahoo.com> writes:
>
> >
> > Dear R forum
> >
> > Suppose I have a data.frame
> >
>
> Say.
>
>
Katherine Gobin yahoo.com> writes:
>
> Dear R forum
>
> Suppose I have a data.frame
>
Say.
[snip]
> How to automatically identify and retain only one column (in this example
column x) among the identical
> columns besides other non-identical columns (viz. id, y and z).
See
?unique
Det
On Mar 28, 2013, at 1:39 AM, Katherine Gobin wrote:
> Dear R forum
>
> Suppose I have a data.frame
>
> df = data.frame(id = c(1:6), x = c(15, 21, 14, 21, 14, 38), y = c(36, 38, 55,
> 11, 5, 18), x.1 = c(15, 21, 14, 21, 14, 38), z = c("D", "B", "A", "F", "H",
> "P"))
>
>
>> df
> id x y
Hi Katherine,
May be this helps:
df[!duplicated(lapply(df,summary))]
# id x y z
#1 1 15 36 D
#2 2 21 38 B
#3 3 14 55 A
#4 4 21 11 F
#5 5 14 5 H
#6 6 38 18 P
#or
df[,colnames(unique(as.matrix(df),MARGIN=2))]
# id x y z
#1 1 15 36 D
#2 2 21 38 B
#3 3 14 55 A
#4 4 21 11 F
#5 5 14
this might screw up the column classes of some of your columns, but it
could be enough for what you're doing :)
# start with a data frame with duplicate columns
v <- data.frame(id = c(1:6), x = c(15, 21, 14, 21, 14, 38), y = c(36, 38,
55, 11, 5, 18), x.1 = c(15, 21, 14, 21, 14, 38), z = c("D", "B
ichner wrote:
From: Gerrit Eichner
Subject: Re: [R] How to delete Identical columns
To: "Katherine Gobin"
Cc: r-help@r-project.org
Date: Thursday, 28 March, 2013, 8:58 AM
Hi, Katherine,
IF the naming scheme of the columns of your data frame is consistently
and if duplicated column
Hi, Katherine,
IF the naming scheme of the columns of your data frame is consistently
and if duplicated columns
appear THEN (something like)
df[ -grep( "\\.", names( df))]
could help. (But it's maybe more efficient to avoid - a priori - producing
duplicated columns, if the data frame is l
8 matches
Mail list logo