select by names(df)

16 views
Skip to first unread message

יוני יצחק

unread,
Oct 7, 2015, 12:39:45 AM10/7/15
to Israel R User Group
שלום לכולם

שאלה די בסיסית אך לא מצאתי לה תשובה ברשת:

האם ניתן לסנן עמודות ב datafarme 2 לפי datafatame 1 בצורה ישירה ?

משהו כזה:


(x<-names(df1


(df_finel<-subset(df2,,x

תודה רבה!

יוני יצחק

Ofrit Lesser

unread,
Oct 7, 2015, 1:21:08 AM10/7/15
to israel-r-...@googlegroups.com

df1 <- list(a = 1, b = "c", c = 1:3)

df2 <- list(v = 2, c = 1:3, h = "h")

 

names(df1)

names(df2)

 

df <- df2[which(names(df2)%in%names(df1))]

df

--
You received this message because you are subscribed to the Google Groups "Israel R User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-g...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.




Avast logo

This email has been checked for viruses by Avast antivirus software.
www.avast.com


Ofrit Lesser

unread,
Oct 7, 2015, 1:27:23 AM10/7/15
to israel-r-...@googlegroups.com

This time with data frames:

 

df1 <- data.frame(a = 1, b = "c", c = 1:3)

df2 <- data.frame(v = 2, c = 1:3, h = "h")

 

names(df1)

names(df2)

 

df <- df2[which(names(df2)%in%names(df1))]

df

 

From: Ofrit Lesser [mailto:ofrit....@gmail.com]
Sent: Wednesday, 7 October 2015 8:21 AM
To: 'israel-r-...@googlegroups.com'
Subject: RE: [Israel RUG] select by names(df)

 

df1 <- list(a = 1, b = "c", c = 1:3)

df2 <- list(v = 2, c = 1:3, h = "h")

 

names(df1)

names(df2)

 

df <- df2[which(names(df2)%in%names(df1))]

df

 

From: israel-r-...@googlegroups.com [mailto:israel-r-...@googlegroups.com] On Behalf Of ???? ????
Sent: Wednesday, 7 October 2015 7:40 AM
To: Israel R User Group
Subject: [Israel RUG] select by names(df)

 

שלום לכולם

--

You received this message because you are subscribed to the Google Groups "Israel R User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-g...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

יוני יצחק

unread,
Oct 8, 2015, 3:58:17 PM10/8/15
to Israel R User Group


ofrit thank you that's exactly what I was looking for


בתאריך יום רביעי, 7 באוקטובר 2015 בשעה 08:27:23 UTC+3, מאת ofrit:

To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-group+unsub...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages