Re: [R] Unique Values per Column

2012-07-23 Thread Jean V Adams
Bert,

Is it important that you end up with a data frame?  If not, it would be 
very easy to generate a list with the unique values for each column.  For 
example:

df <- data.frame(v1 = sample(5, 20, T), v2 = sample(7, 20, T), 
v3 = sample(9, 20, T), v4 = sample(11, 20, T))
lapply(df, unique)

Jean


"Bert Jacobs"  wrote on 07/20/2012 02:37:37 
PM:

> Hi,
> 
> I was wondering what the best way is to create a new dataframe based on 
an
> existing dataframe with only the unique available levels for each column 
(22
> columns in total) in it.
> 
> If some columns have less unique values than others, then those columns 
can
> be filled with blanks for the remaining part. Is it possible to make it 
a
> generic function, which is independent from the column names?
> 
> Thx for helping me out.
> 
> 
> 
> Kind regards,
> 
> Bert

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] Unique Values per Column

2012-07-20 Thread Bert Jacobs
Hi,

I was wondering what the best way is to create a new dataframe based on an
existing dataframe with only the unique available levels for each column (22
columns in total) in it.

If some columns have less unique values than others, then those columns can
be filled with blanks for the remaining part. Is it possible to make it a
generic function, which is independent from the column names?

Thx for helping me out.

 

Kind regards,

Bert

 

 

 


[[alternative HTML version deleted]]

__
R-help@r-project.org 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.