[R] cbind with headers
arun
smartpink111 at yahoo.com
Thu Aug 8 15:56:57 CEST 2013
Hi,
You can save it in file. I copy and paste:
Subtype,Gender,Expression
A,m,-0.54
A,f,-0.8
B,f,-1.03
C,m,-0.41
on the "gedit" and save it as "data1.csv". You might be able to do the same with notepad.
x <- read.csv("data1.csv",header=T,sep=",")
x2 <- read.csv("data2N.csv",header=T,sep=",")
x3 <- cbind(x,x2)
x3
# Subtype Gender Expression Age City
#1 A m -0.54 32 New York
#2 A f -0.80 21 Houston
#3 B f -1.03 34 Seattle
#4 C m -0.41 67 Houston
#or if the dataset is small as in the example
x<- read.table(text="
Subtype,Gender,Expression
A,m,-0.54
A,f,-0.8
B,f,-1.03
C,m,-0.41
",sep=",",header=TRUE,stringsAsFactors=FALSE)
x2<- read.table(text="
Age,City
32,New York
21,Houston
34,Seattle
67,Houston
",sep=",",header=TRUE,stringsAsFactors=FALSE)
cbind(x,x2)
# Subtype Gender Expression Age City
#1 A m -0.54 32 New York
#2 A f -0.80 21 Houston
#3 B f -1.03 34 Seattle
#4 C m -0.41 67 Houston
A.K.
Hi,
I can't seem to get this to work:
http://www.endmemo.com/program/R/cbind.php
Do
I save the data as data1.csv in note pad and pull in the file? Do I
type
data1.csv<-Subtype,Gender,Expression,A,m,-0.54,A,f,-0.8,B,f,-1.03,C,m,-0.41??
I can do a simple matrix. But, I want to have headers and data to combine.
Simple Matrix I combined.
> m<-as.data.frame(matrix(c(1:6),ncol=2))
> n<-as.data.frame(matrix(c(7:12),ncol=2))
> m
V1 V2
1 1 4
2 2 5
3 3 6
> n
V1 V2
1 7 10
2 8 11
3 9 12
> Mary<-cbind(m,n)
> Mary
V1 V2 V1 V2
1 1 4 7 10
2 2 5 8 11
3 3 6 9 12
More information about the R-help
mailing list