[R] Subseting

arun smartpink111 at yahoo.com
Thu Aug 2 14:25:52 CEST 2012


Hi,
Try this:

Here, in the example dataset, you have 3 banks.  Suppose, I want to delete 2 banks randomly out of 3, (you can name your specific banks to delete),
dat1<-read.table(text="
Year  Name totalliabilties assets
1990  a              90            10
1991  a              89            48
1992  a              87            34
1993  a              56            05
1990  b              90            11
1991  b              69            43
1992  b              37            34
1993  b              46            17
1990  c              55            10
1991  c              67            18
1992  c              34            24
1993  c              53            35
",sep="",header=TRUE)
 names1<-sample(letters[1:3],2)
 names1
#[1] "b" "a"
subset(dat1,!dat1$Name%in%names1)
#   Year Name totalliabilties assets
#9  1990    c              55     10
#10 1991    c              67     18
#11 1992    c              34     24
#12 1993    c              53     35
A.K.





----- Original Message -----
From: Akhil dua <akhil.dua.12 at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Thursday, August 2, 2012 4:44 AM
Subject: [R] Subseting

Hi everyone

I have banking data set in long format with 4 columns.One of these columns
is bank name which consist of 49 banks and I want the data for only 40
banks out of these 49
so can anyone help me on how to get this 40 banks data

My data looks like

Year  Name totalliabilties assets
1990  a              90            10
1991  a              89            48
1992  a              87            34
1993  a              56            05
1990  b              90            11
1991  b              69            43
1992  b              37            34
1993  b              46            17
1990  c              55            10
1991  c              67            18
1992  c              34            24
1993  c              53            35

please keep in mind that I have 49 firms so I cant do
object<-data[,c("names of the banks I need the data")]
and then extract the data for these banks out of the whole sample

    [[alternative HTML version deleted]]

______________________________________________
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