Inchallah Yarab
2009-Aug-12 12:03 UTC
[R] Re : paste first row string onto every string in column
Try this , save your data in C:/
and write this
(data <- read.csv2("c:/jill.csv", sep=","))
(C<-data[1,])
A <- numeric(4)
B <- numeric(4)
for (i in 1 :4){
A[i] <- paste(data[1,i],data[2,i])
B[i] <- paste(data[1,i],data[3,i])
}
A
B
(data1 <- rbind(as.character(A),as.character(B)))
(data2 <- rbind(C,data1))
normaly that gives that> (data <- read.csv2("c:/jill.csv", sep=","))
V1 V2 V3 V4
1 DPA1* DPA1* DPB1* DPB1*
2 103 104 401 601
3 103 103 301 402> (C<-data[1,])
V1 V2 V3 V4
1 DPA1* DPA1* DPB1* DPB1*> A <- numeric(4)
> B <- numeric(4)
> for (i in 1 :4){
+ A[i] <- paste(data[1,i],data[2,i])
+ B[i] <- paste(data[1,i],data[3,i])
+ }> A
[1] "DPA1* 103" "DPA1* 104" "DPB1* 401"
"DPB1* 601"> B
[1] "DPA1* 103" "DPA1* 103" "DPB1* 301"
"DPB1* 402">
> (data1 <- rbind(as.character(A),as.character(B)))
[,1] [,2] [,3] [,4]
[1,] "DPA1* 103" "DPA1* 104" "DPB1* 401"
"DPB1* 601"
[2,] "DPA1* 103" "DPA1* 103" "DPB1* 301"
"DPB1* 402"> (data2 <- rbind(C,data1))
V1 V2 V3 V4
1 DPA1* DPA1* DPB1* DPB1*
2 DPA1* 103 DPA1* 104 DPB1* 401 DPB1* 601
3 DPA1* 103 DPA1* 103 DPB1* 301 DPB1* 402>
Hope that helps!!!
inchallah yarab
________________________________
De : Jill Hollenbach <jhollenbach@chori.org>
À : r-help@r-project.org
Envoyé le : Mercredi, 12 Août 2009, 3h48mn 37s
Objet : [R] paste first row string onto every string in column
Hi,
I am trying to edit a data frame such that the string in the first line is
appended onto the beginning of each element in the subsequent rows. The data
looks like this:
> df
V1 V2 V3 V4
1 DPA1* DPA1* DPB1* DPB1*
2 0103 0104 0401 0601
3 0103 0103 0301 0402
.
.
and what I want is this:
>dfnew
V1 V2 V3 V4
1 DPA1* DPA1* DPB1* DPB1*
2 DPA1*0103 DPA1*0104 DPB1*0401 DPB1*0601
3 DPA1*0103 DPA1*0103 DPB1*0301 DPB1*0402
any help is much appreciated, I am new to this and struggling.
Jill
___
Jill Hollenbach, PhD, MPH
Assistant Staff Scientist
Center for Genetics
Children's Hospital Oakland Research Institute
jhollenbach@chori.org
--
View this message in context:
http://www.nabble.com/paste-first-row-string-onto-every-string-in-column-tp24928720p24928720.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
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.
[[alternative HTML version deleted]]
