[R] Using cbind to combine data frames and preserve header/names
Rainer Schuermann
rainer.schuermann at gmx.net
Sat Nov 17 08:40:07 CET 2012
Not sure where the problem is?
Since you did not provide sample data, I took the iris data set and converted it to your structure:
x <- cbind( iris[5], iris[1:3] )
head( x )
Species Sepal.Length Sepal.Width Petal.Length
1 setosa 5.1 3.5 1.4
2 setosa 4.9 3.0 1.4
3 setosa 4.7 3.2 1.3
4 setosa 4.6 3.1 1.5
5 setosa 5.0 3.6 1.4
6 setosa 5.4 3.9 1.7
Does that look like your data?
If so,
xbin <- cbind( x[1], binarize( x[2:4] ) )
gives a result that should look just like what you want:
head( xbin )
Species Sepal.Length Sepal.Width Petal.Length
1 setosa 1 0 0
2 setosa 1 0 0
3 setosa 1 0 0
4 setosa 1 0 0
5 setosa 1 0 0
6 setosa 1 0 0
Using
xbin <- cbind( x$Species, binarize( x[-1] ) )
doesn't make a difference.
Or did I not understand your problem well?
Rgds,
Rainer
On Saturday 17 November 2012 00:39:02 Brian Feeny wrote:
> I have a dataframe that has a header like so:
>
> class value1 value2 value3
>
> class is a factor
>
> the actual values in the columns value1, value2 and value3 are 0-255, I wish to binarize these using biclust.
> I can do this like so:
>
> binarize(dataframe[,-1])
>
> this will return a dataframe, but then I lose my first column class, so I thought I could combine it like so:
>
> dataframe <- cbind(dataframe$label, binarize(dataframe[,-1]))
>
> but then I lose my header (names).............how can I do the above operation and keep my header in tact?
>
> Basically i just want to binarize everything but the first column (since its a factor column and not numeric).
>
> Thank you for any help you can give me, I am relatively new to R.
>
> Brian
>
> ______________________________________________
> R-help at 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.
More information about the R-help
mailing list