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]]
On 02.08.2012, at 10:44, Akhil dua wrote:> 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")]That would actually rather be data[data$Name %in% names, ] wouldn't it? You want to extract the rows that belong to a bank you want to retain? what are firms? what have the firms to do with the banks and their names?> 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.
data[data$Name %in% names, ] should work then. You do know which 40 of your 49 banks you want, right? put their names in the "names" variable above. If you want random 40 banks you can do something like this: allNames<-unique(data$Name) names<-sample(allNames,40) Does that help? You really aren't explaining your problem well^^ On 02.08.2012, at 11:18, Akhil dua wrote:> sry its not firms > its banks > > On Thu, Aug 2, 2012 at 2:42 PM, Jessica Streicher <j.streicher at micromata.de> wrote: > > On 02.08.2012, at 10:44, Akhil dua wrote: > > > 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")] > > That would actually rather be > data[data$Name %in% names, ] > > wouldn't it? You want to extract the rows that belong to a bank you want to retain? > > what are firms? what have the firms to do with the banks and their names? > > > 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. > >
data[!(data$Name %in% names), ] then, and "names" having the 9 names you want to dismiss. Also please reply to the list as well if you answer, otherwise others won't know of the progress made. On 02.08.2012, at 11:48, Akhil dua wrote:> This is the only issue actually > I dotn want to take the pain of writing names of 40 companies > rather than this i want to remove the date for 9 companies which i dont need > > On Thu, Aug 2, 2012 at 3:00 PM, Jessica Streicher <j.streicher at micromata.de> wrote: > data[data$Name %in% names, ] > > should work then. You do know which 40 of your 49 banks you want, right? > put their names in the "names" variable above. > > If you want random 40 banks you can do something like this: > > allNames<-unique(data$Name) > names<-sample(allNames,40) > > Does that help? You really aren't explaining your problem well^^ > > On 02.08.2012, at 11:18, Akhil dua wrote: > > > sry its not firms > > its banks > > > > On Thu, Aug 2, 2012 at 2:42 PM, Jessica Streicher <j.streicher at micromata.de> wrote: > > > > On 02.08.2012, at 10:44, Akhil dua wrote: > > > > > 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")] > > > > That would actually rather be > > data[data$Name %in% names, ] > > > > wouldn't it? You want to extract the rows that belong to a bank you want to retain? > > > > what are firms? what have the firms to do with the banks and their names? > > > > > 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. > > > > > >
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.