Hi everyone,
I have a question on selecting and grouping elements of a data frame. For example:
A.df<- [ a c 0.9
b x 0.8
b z 0.5
c y 0.9
c x 0.7
c z 0.6]
I want to create a list of a data frame that gives me the unique values of column 1 of A.df so that i can create intersects. That is:
B[a]<- [ c 0.9]
B[b]<- [ x 0.8
z 0.5]
B[c]<- [ y 0.9
x 0.7
z 0.6]
B[c] n B[b] <- c(x,z)
How can I accomplish this?
Thanks,
Al
grouping elements of a data frame
3 messages · Nuri Alpay Temiz, David Winsemius, arun
On Jan 15, 2013, at 9:10 AM, Nuri Alpay Temiz wrote:
Hi everyone,
I have a question on selecting and grouping elements of a data frame. For example:
A.df<- [ a c 0.9
b x 0.8
b z 0.5
c y 0.9
c x 0.7
c z 0.6]
That is not R code. Matlab?, Python?
I want to create a list of a data frame that gives me the unique values of column 1 of A.df so that i can create intersects. That is:
B[a]<- [ c 0.9]
B[b]<- [ x 0.8
z 0.5]
B[c]<- [ y 0.9
x 0.7
z 0.6]
B[c] n B[b] <- c(x,z)
That's some sort of coded message? We are supposed to know what the "n" operation will do when assigned a vector? Assuming your really do have a dataframe named B: intersect(B$c, B$b) Please code up examples in R in the future.
David Winsemius Alameda, CA, USA
Hi, Try this: The last part was not clear. A.df<-read.table(text=" ??? ??? a c 0.9 ??????????? b? x 0.8 ??????????? b z 0.5 ??????????? c y 0.9 ??????????? c x 0.7 ??????????? c z 0.6 ",sep="",header=FALSE,stringsAsFactors=FALSE) ?lst1<-split(A.df[,-1],A.df$V1) lst1 #$a #? V2? V3 #1? c 0.9 # #$b #? V2? V3 #2? x 0.8 #3? z 0.5 # #$c #? V2? V3 #4? y 0.9 #5? x 0.7 #6? z 0.6 A.K. ----- Original Message ----- From: Nuri Alpay Temiz <alpaytemiz at outlook.com> To: R-help at r-project.org Cc: Sent: Tuesday, January 15, 2013 12:10 PM Subject: [R] grouping elements of a data frame Hi everyone, I have a question on selecting and grouping elements of a data frame. For example: A.df<- [ a c 0.9 ? ? ? ? ? ? b? x 0.8 ? ? ? ? ? ? b z 0.5 ? ? ? ? ? ? c y 0.9 ? ? ? ? ? ? c x 0.7 ? ? ? ? ? ? c z 0.6] I want to create a list of a data frame that gives me the unique values of column 1 of A.df so that i can create intersects. That is: B[a]<- [ c 0.9] B[b]<- [ x 0.8 ? ? ? ? ? ? z 0.5] B[c]<- [ y 0.9 ? ? ? ? ? ? x 0.7 ? ? ? ? ? ? z 0.6] B[c] n B[b] <- c(x,z) How can I accomplish this? Thanks, Al ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ______________________________________________ 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.