Re: [R] multi variate plot with string data
Thanks!! this works perfectly dat = data.frame(Aggressive = data_set$var1 , Behaviour=data_set$var2) plot(table(dat)) ...its better than a stacked boxplot as it gives also different width of columns on the diagram...an extra layer of information. frenchcr wrote: > > > Ive got two columns in data_set that are strings > > the first column is called "character" and has levels: > good, bad, ugly > > the second column is called "abusive" and has levels: > aggressive, moderately aggressive, mildly aggressive > > > I want to do a stacked boxplot that has this sort of structure: > > %aggressive %aggressive > %aggressive > %moderately aggressive %moderately aggressive %moderately > aggressive > %mildly aggressive %mildly aggressive %mildly > aggressive > %not agressive %not agressive %not > agressive > >bad good > ugly > > > ...with legend at the size showing which colour each of the "abusive" > levels takes. > > > How is it done? > -- View this message in context: http://old.nabble.com/multi-variate-plot-with-string-data-tp26517211p26534782.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.
Re: [R] multi variate plot with string data
is there something wrong with the way i asked the question frenchcr wrote: > > > Ive got two columns in data_set that are strings > > the first column is called "character" and has levels: > good, bad, ugly > > the second column is called "abusive" and has levels: > aggressive, moderately aggressive, mildly aggressive > > > I want to do a stacked boxplot that has this sort of structure: > > %aggressive %aggressive > %aggressive > %moderately aggressive %moderately aggressive %moderately > aggressive > %mildly aggressive %mildly aggressive %mildly > aggressive > %not agressive %not agressive %not > agressive > >bad good > ugly > > > ...with legend at the size showing which colour each of the "abusive" > levels takes. > > > How is it done? > -- View this message in context: http://old.nabble.com/multi-variate-plot-with-string-data-tp26517211p26525342.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.
[R] multi variate plot with string data
Ive got two columns in data_set that are strings the first column is called "character" and has levels: good, bad, ugly the second column is called "abusive" and has levels: aggressive, moderately aggressive, mildly aggressive I want to do a stacked boxplot that has this sort of structure: %aggressive %aggressive %aggressive %moderately aggressive %moderately aggressive %moderately aggressive %mildly aggressive %mildly aggressive %mildly aggressive %not agressive %not agressive %not agressive bad good ugly ...with legend at the size showing which colour each of the "abusive" levels takes. How is it done? -- View this message in context: http://old.nabble.com/multi-variate-plot-with-string-data-tp26517211p26517211.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.
[R] how do i persuade IT to install R on PCs ?? ...and should I ??
Please help me persuade IT to install R on my computer! All suggestions welcome. Our IT department run scared when you mention software that they have no working experience of. I need to know the pros and cons of having R on corporate desktops. Please no funny stuff, this is quite a serious issue for us. Pros and cons would be good. Thanks. -- View this message in context: http://old.nabble.com/how-do-i-persuade-IT-to-install-R-on-PCs...and-should-Itp26464163p26464163.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.
[R] other decriptive stats packages
i just found the following list, i wondered if anybody could add to this as i have to characterize a large data set and am new to R...the list below was so helpfulcan you add to this??? Just to forestall confusion amongst those who would like to use one of the functions called "describe"... Hmisc package - describe numeric name count of observations count of missing values count of unique values mean seven quantiles five lowest and highest values discrete (factor or numeric with <= 10 unique values) - as for numeric, but no mean, quantiles or low/high values and including a frequency/percent display for each value. psych package - describe item name item number number of valid cases mean standard deviation median mad: median absolute deviation (from the median) minimum maximum skew (optional) kurtosis (optional) standard error prettyR package - describe numeric name mean median var sd valid.n the above are the defaults - the user can specify the name(s) of any function(s) as an argument to the function to customize the display. factor name count for each value percent for each value modal value count of missing values logical name count of FALSE count of TRUE percent of TRUE count of missing values are there any more packages that help decribe and explore data sets -- View this message in context: http://old.nabble.com/other-decriptive-stats-packages-tp26460757p26460757.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.
[R] what do i do to fix missing packages...see error
> exampledata <- rnorm(1) > summary(exampledata) Min. 1st Qu.Median Mean 3rd Qu. Max. -4.03 -0.666200 -0.023390 -0.009384 0.664700 4.092000 > desc <- function(mydata) { +require(e1071) +quantls <- quantile(x=mydata, probs=seq(from=0, to=1, by=0.25)) +themean <- mean(mydata) +thesd <- sd(mydata) +kurt <- kurtosis(mydata) +skew <- skewness(mydata) +retlist <- list(Quantiles=quantls, Mean=themean, StandDev=thesd, +Skewness=skew, Kurtosis=kurt) +return(retlist) + } > descstats <- desc(exampledata) Loading required package: e1071 Error in desc(exampledata) : could not find function "kurtosis" In addition: Warning message: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called 'e1071' -- View this message in context: http://old.nabble.com/what-do-i-do-to-fix-missing-packages...see-error-tp26460061p26460061.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.
[R] non homogeneous poisson process
I want to do a non homogeneous poisson process model in R. Any advice, or know of places where i can get some, ive googled it but nothing came up relating to R. -- View this message in context: http://old.nabble.com/non-homogeneous-poisson-process-tp26378037p26378037.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.
[R] in excel i can sort my dataset, what do i use in R
In excel a handy tool is the sort data by column ...i.e. i can highlight the whole dataset and sort it according to a particular column...like sort the data in a column in acending or decending order where all the other columns change aswell. I need to do this in R now but dont know how. ...heres an example... Say I have dataset... Header 1Header 2Header 3 1 3 Working 12 2 4 Off1 3 5 Works2 4 2 Works13 5 4 Off5 ...and i want to sort the data by putting the values in the third column in acending order, like this... Header 1Header 2Header 3 1 4 Off1 2 5 Works2 3 4 Off5 4 3 Working 12 5 2 Works13 ...although im sorting column three in acending order all the rows shuffle so that the parameters in each row stay aligned. How do i do this in R? -- View this message in context: http://old.nabble.com/in-excel-i-can-sort-my-dataset%2C-what-do-i-use-in-R-tp26377540p26377540.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.
[R] printing a single row, but dont know which row to print
I have 20 columns of data, and in column 5 I have a value of 17600 but I dont know which row this value is in (i have over 300,000 rows). I'm trying to do 2 things: 1) I want to find out which row in column 5 has this number in it. 2) Then I want to print out that row with all the column headers so i can look at the other parameters in the row that are associated with this value. How do i do it? -- View this message in context: http://old.nabble.com/printing-a-single-row%2C-but-dont-know-which-row-to-print-tp26376647p26376647.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.
Re: [R] re move row if the column "date_abandoned" has a date in it
this works perfectly... new_data5 <- new_data4[nchar(new_data4$date_abandoned) != 8, ] ...and i can now think of a few different ways to manipulate my data with what ive learned from these tricks, thanks alot David! David Winsemius wrote: > > > On Nov 15, 2009, at 11:00 AM, frenchcr wrote: > >> >> >> Yes they are not in date format, theyre just characters. >> >> the earliest date is 1601 i originally had one of 0101 00 00 >> (101 years >> BC)...this was a software problem. >> >>> table(nchar(new_data4$date_abandoned)) >> >> 2 8 >> 315732263 >> >> The 315732 are empty fields i thought. > > They are actually 2 characters wide. > >> The 263 are dates, i want to remove their rows. > > If you want to "remove" the ones that are _not_ 8 characters long, then: > > new_data5 <- new_data4[nchar(new_data4$date_abandoned) != 8, ] > > or: > > new_data5 <- subset(new_data4, date_abandoned != 8) > > -- > David. > >> >> >> >> David Winsemius wrote: >>> >>> >>> On Nov 14, 2009, at 8:43 PM, frenchcr wrote: >>> >>>> >>>> sorry David, >>>> >>>> im really new to R (my first week) and appreciate your help. Also I >>>> dont >>>> always know what info to give people on the forum (although im >>>> starting to >>>> catch the drift). >>>> >>>> heres what i get... >>>> >>>> summary(new_data4$date_abandoned) >>>> Min.1st Qu.Median Mean 3rd Qu. >>>> Max. NA's >>>> 1601 1998 2001 1993 2004 2009 315732 >>> >>> So new_data4$data_abandoned is not of type "Date" and is instead a >>> character vector. >>> >>> If you are resisting turning it into a date and want to work with >>> characters, you can, you just need to deal somehow with the items >>> that >>> are not 8 characters wide. What does 315732 represent? How were we >>> supposed to interpret the starting "date" you gave of "0101"? >>> >>>> nchar("101") >>> [1] 7 >>> >>> What does table(nchar(new_data4$date_abandoned)) give you? >>>> >>>>> ls() >>>> [1] "data" "new_data" "new_data2" "new_data3" "new_data4" >>>>> small <- head(new_data4, 20) >>>>> dump("small", 20) >>>> Error in dump("small", 20) : cannot write to this connection >>> >>> >>> Well, sorry, I meant to type dump("small", stdout()) ... As per the >>> Posting Guide. >>> >>> -- >>> David. >>>> >>>> David Winsemius wrote: >>>>> >>>>> >>>>> On Nov 14, 2009, at 5:24 PM, frenchcr wrote: >>>>> >>>>>> >>>>>> >>>>>> I tried the following but it does the opposite of what i want: >>>>>> >>>>>> new_data5 <- subset(new_data4, date_abandoned > "0101") >>>>>> >>>>>> I want to remove the rows with dates and leave just the rows >>>>>> without >>>>>> a date. >>>>>> >>>>>> This removes all the rows that dont have a date in the >>>>>> date_abandoned column >>>>>> >>>>>> ...on a positive note, as i did this next... >>>>>> >>>>>> dim(new_data5) >>>>>> [1] 263 80 >>>>>> >>>>>> i now know that i have 263 dates in that column :) >>>>>> >>>>>> I want to remove the 263 rows with dates and leave just the rows >>>>>> without a >>>>>> date. >>>>> >>>>> Con=me on frenchcr. Stop making us guess. Give us enough >>>>> information >>>>> to work with. You asked for something which I construed as saying >>>>> you >>>>> wanted dates greater than the the first day of the year 101. You >>>>> did >>>>> not address this question. >>>>> >>>>> What do you get with str(new_data4) and >>>>> summary(new_data4$date_abandoned) ? In order to know what sort of >>>>
Re: [R] re move row if the column "date_abandoned" has a date in it
Yes they are not in date format, theyre just characters. the earliest date is 1601 i originally had one of 0101 00 00 (101 years BC)...this was a software problem. > table(nchar(new_data4$date_abandoned)) 2 8 315732263 The 315732 are empty fields i thought. The 263 are dates, i want to remove their rows. David Winsemius wrote: > > > On Nov 14, 2009, at 8:43 PM, frenchcr wrote: > >> >> sorry David, >> >> im really new to R (my first week) and appreciate your help. Also I >> dont >> always know what info to give people on the forum (although im >> starting to >> catch the drift). >> >> heres what i get... >> >> summary(new_data4$date_abandoned) >> Min.1st Qu.Median Mean 3rd Qu. >> Max. NA's >> 1601 1998 2001 1993 2004 2009 315732 > > So new_data4$data_abandoned is not of type "Date" and is instead a > character vector. > > If you are resisting turning it into a date and want to work with > characters, you can, you just need to deal somehow with the items that > are not 8 characters wide. What does 315732 represent? How were we > supposed to interpret the starting "date" you gave of "0101"? > > > nchar("101") > [1] 7 > > What does table(nchar(new_data4$date_abandoned)) give you? >> >>> ls() >> [1] "data" "new_data" "new_data2" "new_data3" "new_data4" >>> small <- head(new_data4, 20) >>> dump("small", 20) >> Error in dump("small", 20) : cannot write to this connection > > > Well, sorry, I meant to type dump("small", stdout()) ... As per the > Posting Guide. > > -- > David. >> >> David Winsemius wrote: >>> >>> >>> On Nov 14, 2009, at 5:24 PM, frenchcr wrote: >>> >>>> >>>> >>>> I tried the following but it does the opposite of what i want: >>>> >>>> new_data5 <- subset(new_data4, date_abandoned > "0101") >>>> >>>> I want to remove the rows with dates and leave just the rows without >>>> a date. >>>> >>>> This removes all the rows that dont have a date in the >>>> date_abandoned column >>>> >>>> ...on a positive note, as i did this next... >>>> >>>> dim(new_data5) >>>> [1] 263 80 >>>> >>>> i now know that i have 263 dates in that column :) >>>> >>>> I want to remove the 263 rows with dates and leave just the rows >>>> without a >>>> date. >>> >>> Con=me on frenchcr. Stop making us guess. Give us enough information >>> to work with. You asked for something which I construed as saying you >>> wanted dates greater than the the first day of the year 101. You did >>> not address this question. >>> >>> What do you get with str(new_data4) and >>> summary(new_data4$date_abandoned) ? In order to know what sort of >>> comparison to use we need to know what the data looks like. >>> >>> Even better if you offered the output from: >>> >>> small <- head(new_data4, 20) >>> dump("small", 20), >>> >>> -- >>> David >>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> David Winsemius wrote: >>>>> >>>>> >>>>> On Nov 14, 2009, at 1:21 PM, frenchcr wrote: >>>>> >>>>>> >>>>>> >>>>>> I want to go through a column in data called >>>>> >>>>> Bad name for a data.frame. Fortunes, "dog" and all that. >>>>> >>>>>> date_abandoneddata["date_abandoned"]and remove all the >>>>>> rows >>>>>> that >>>>>> have numbers greater than 1,010,000. >>>>> >>>>> Are you doing archeology? Given what you say next I wondered what >>>>> range you were really asking for. >>>>> >>>>>> >>>>>> The dates are in the format 20091114 so i'm just going to treat >>>>>> them >>>>>> as >>>>>> numbers for clean up purposes. >>>>>> >>>>>> >>>>>> I know that
Re: [R] re move row if the column "date_abandoned" has a date in it
sorry David, im really new to R (my first week) and appreciate your help. Also I dont always know what info to give people on the forum (although im starting to catch the drift). heres what i get... summary(new_data4$date_abandoned) Min.1st Qu.Median Mean 3rd Qu. Max. NA's 1601 1998 2001 1993 2004 2009 315732 > ls() [1] "data" "new_data" "new_data2" "new_data3" "new_data4" > small <- head(new_data4, 20) > dump("small", 20) Error in dump("small", 20) : cannot write to this connection > frenchcr David Winsemius wrote: > > > On Nov 14, 2009, at 5:24 PM, frenchcr wrote: > >> >> >> I tried the following but it does the opposite of what i want: >> >> new_data5 <- subset(new_data4, date_abandoned > "0101") >> >> I want to remove the rows with dates and leave just the rows without >> a date. >> >> This removes all the rows that dont have a date in the >> date_abandoned column >> >> ...on a positive note, as i did this next... >> >> dim(new_data5) >> [1] 263 80 >> >> i now know that i have 263 dates in that column :) >> >> I want to remove the 263 rows with dates and leave just the rows >> without a >> date. > > Con=me on frenchcr. Stop making us guess. Give us enough information > to work with. You asked for something which I construed as saying you > wanted dates greater than the the first day of the year 101. You did > not address this question. > > What do you get with str(new_data4) and > summary(new_data4$date_abandoned) ? In order to know what sort of > comparison to use we need to know what the data looks like. > > Even better if you offered the output from: > > small <- head(new_data4, 20) > dump("small", 20), > > -- > David > >> >> >> >> >> >> >> >> David Winsemius wrote: >>> >>> >>> On Nov 14, 2009, at 1:21 PM, frenchcr wrote: >>> >>>> >>>> >>>> I want to go through a column in data called >>> >>> Bad name for a data.frame. Fortunes, "dog" and all that. >>> >>>> date_abandoneddata["date_abandoned"]and remove all the rows >>>> that >>>> have numbers greater than 1,010,000. >>> >>> Are you doing archeology? Given what you say next I wondered what >>> range you were really asking for. >>> >>>> >>>> The dates are in the format 20091114 so i'm just going to treat them >>>> as >>>> numbers for clean up purposes. >>>> >>>> >>>> I know that i use subset but not sure how to proceed from there. >>> >>> subdata <- subset(data, date_abandoned > "0101"() >>> >>> >>> The problem with > "101" is that your specified minimum point had >>> an insufficient number of "places" to be in MMDD format. >>> >>> -- >>> >>> David Winsemius, MD >>> Heritage Laboratories >>> West Hartford, CT >>> >>> __ >>> 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. >>> >>> >> >> -- >> View this message in context: >> http://old.nabble.com/remove-row-if-the-column-%22date_abandoned%22-has-a-date-in-it-tp26352457p26354446.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. > > David Winsemius, MD > Heritage Laboratories > West Hartford, CT > > __ > 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. > > -- View this message in context: http://old.nabble.com/remove-row-if-the-column-%22date_abandoned%22-has-a-date-in-it-tp26352457p26355689.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.
Re: [R] re move row if the column "date_abandoned" has a date in it
I tried the following but it does the opposite of what i want: new_data5 <- subset(new_data4, date_abandoned > "0101") I want to remove the rows with dates and leave just the rows without a date. This removes all the rows that dont have a date in the date_abandoned column ...on a positive note, as i did this next... dim(new_data5) [1] 263 80 i now know that i have 263 dates in that column :) I want to remove the 263 rows with dates and leave just the rows without a date. David Winsemius wrote: > > > On Nov 14, 2009, at 1:21 PM, frenchcr wrote: > >> >> >> I want to go through a column in data called > > Bad name for a data.frame. Fortunes, "dog" and all that. > >> date_abandoneddata["date_abandoned"]and remove all the rows >> that >> have numbers greater than 1,010,000. > > Are you doing archeology? Given what you say next I wondered what > range you were really asking for. > >> >> The dates are in the format 20091114 so i'm just going to treat them >> as >> numbers for clean up purposes. >> >> >> I know that i use subset but not sure how to proceed from there. > > subdata <- subset(data, date_abandoned > "0101"() > > > The problem with > "101" is that your specified minimum point had > an insufficient number of "places" to be in MMDD format. > > -- > > David Winsemius, MD > Heritage Laboratories > West Hartford, CT > > __ > 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. > > -- View this message in context: http://old.nabble.com/remove-row-if-the-column-%22date_abandoned%22-has-a-date-in-it-tp26352457p26354446.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.
[R] re move row if the column "date_abandoned" has a date in it
I want to go through a column in data called date_abandoneddata["date_abandoned"]and remove all the rows that have numbers greater than 1,010,000. The dates are in the format 20091114 so i'm just going to treat them as numbers for clean up purposes. I know that i use subset but not sure how to proceed from there. -- View this message in context: http://old.nabble.com/remove-row-if-the-column-%22date_abandoned%22-has-a-date-in-it-tp26352457p26352457.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.
Re: [R] cleanse columns and unwanted rows
The full code and error message i get is... > cleanse <- function(a){ + data1<-a + for (i in 1:dim(data1)[1]) + { + if (data1[i,"legal_status"] == "Private"){ + data1[i,"legal_status"]<-data1[-i,] + if (data1[i,"legal_status"] == "Private (Op"){ + data1[i,"legal_status"]<-data1[-i,] + if (data1[i,"legal_status"] == "Unknown"){ + data1[i,"legal_status"]<-data1[-i,] + } +} + } + } + return(data1) + } > new_data<-cleanse(data) Error in if (data1[i, "legal_status"] == "Private (Op") { : missing value where TRUE/FALSE needed In addition: There were 50 or more warnings (use warnings() to see the first 50) > frenchcr wrote: > > hello folks, > > Im trying to clean out a large file with data i dont need. > The column im manipulating in the file is called "legal_status" > There are three kinds of rows i want to remove. Those that have "Private", > "Private (Op", or "Unknown" in the legal_status column. > > > I wrote this code but i get errors and it says im missing a TRUE/ False > thingy...im lost...heres the code... > > > > cleanse <- function(a){ > data1<-a > > for (i in 1:dim(data1)[1]) > { > if (data1[i,"legal_status"] == "Private") > { > data1[i,"legal_status"]<-data1[-i,"legal_status"] > } > if (data1[i,"legal_status"] == "Private (Op"){ > data1[i,"legal_status"]<-data1[-i,"legal_status"] > } > if (data1[i,"legal_status"] == "Unknown"){ > data1[i,"legal_status"]<-data1[-i,"legal_status"] > } > } > > return(data1) > } > new_data<-cleanse(data) > > > > > Any ideas? > -- View this message in context: http://old.nabble.com/cleanse-columns-and-unwanted-rows-tp26342169p26350857.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.
Re: [R] cleanse columns and unwanted rows
The solution is much simpler (thanks Phil!) new_data = data[!data$"legal status" %in% c("Private","Private (Op","Unknown"),] ...works nicely. frenchcr wrote: > > hello folks, > > Im trying to clean out a large file with data i dont need. > The column im manipulating in the file is called "legal_status" > There are three kinds of rows i want to remove. Those that have "Private", > "Private (Op", or "Unknown" in the legal_status column. > > > I wrote this code but i get errors and it says im missing a TRUE/ False > thingy...im lost...heres the code... > > > > cleanse <- function(a){ > data1<-a > > for (i in 1:dim(data1)[1]) > { > if (data1[i,"legal_status"] == "Private") > { > data1[i,"legal_status"]<-data1[-i,"legal_status"] > } > if (data1[i,"legal_status"] == "Private (Op"){ > data1[i,"legal_status"]<-data1[-i,"legal_status"] > } > if (data1[i,"legal_status"] == "Unknown"){ > data1[i,"legal_status"]<-data1[-i,"legal_status"] > } > } > > return(data1) > } > new_data<-cleanse(data) > > > > > Any ideas? > -- View this message in context: http://old.nabble.com/cleanse-columns-and-unwanted-rows-tp26342169p26350874.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.
[R] cleanse columns and unwanted rows
hello folks, Im trying to clean out a large file with data i dont need. The column im manipulating in the file is called "legal status" Their are three kinds of rows i want to remove. Those that have "Private", "Private (Op", or "Unknown" in the legal_status column. I wrote this code but it syas im missing a TRUE/ False thingy...im lost...heres the code... cleanse <- function(a){ data1<-a for (i in 1:dim(data1)[1]) { if (data1[i,"legal_status"] == "Private") { data1[i,"legal_status"]<-data1[-i,"legal_status"] } if (data1[i,"legal_status"] == "Private (Op"){ data1[i,"legal_status"]<-data1[-i,"legal_status"] } if (data1[i,"legal_status"] == "Unknown"){ data1[i,"legal_status"]<-data1[-i,"legal_status"] } } return(data1) } new_data<-cleanse(data) Any ideas? -- View this message in context: http://old.nabble.com/cleanse-columns-and-unwanted-rows-tp26342169p26342169.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.
Re: [R] Turn dates into age
why do you use 365.25? dates<-as.character(data[,"date_commissioned"]); # convert dates to characters #dates[1:10] #[1] "19910101" "19860101" "19910101" "19860101" "19910101" "19910101" "19910101" "19910101" "19910101" "19910101" dateObs <- as.Date(dates,format="%Y%m%d") #dateObs[1:10] #[1] "1991-01-01" "1986-01-01" "1991-01-01" "1986-01-01" "1991-01-01" "1991-01-01" "1991-01-01" "1991-01-01" "1991-01-01" "1991-01-01" today <- Sys.Date() x.date <- as.Date(dateObs, format="%Y%m%d") AGE <- round(as.vector(difftime(today , x.date, units='day') / 365.25)) frenchcr wrote: > > > it sure does thank you! > > >> will this work for you >> >> x <- c('19910101', '19950302', '20010502') >> today <- Sys.Date() >> x.date <- as.Date(x, format="%Y%m%d") >> round(as.vector(difftime(today , x.date, units='day') / 365.25)) > [1] 19 15 9 >> > > > On Sun, Nov 8, 2009 at 2:44 PM, wrote: >> Hi Jim, >> >> Thanks for the quick reply...not sure what you mean by frame of >> reference(only been using R for 4 days)...to clarify, i need to turn my >> dates from 1999-10-01 into 1999 then i subtract 2009 -1999 to get an age >> of 10. The column im working on has 312,000 rows and some have NA in them >> as we have no dates for that item. >> >> To recap, the column is just a bunch of dates with some field empty, i >> want to change the column from "date of commision" to "age of asset" >> >> Cheers >> Chris. > > > > > jholtman wrote: >> >> What is the frame of reference to determine the age? Check out >> 'difftime'. >> >> On Sun, Nov 8, 2009 at 1:50 PM, frenchcr wrote: >>> >>> Ive got a big column of dates (also some fields dont have a date so they >>> have >>> NA instead), >>> that i have converted into date format as so... >>> >>> >>> dates<-as.character(data[,"date_commissioned"]); # converted dates to >>> characters >>> dates[1:10] >>> [1] "19910101" "19860101" "19910101" "19860101" "19910101" "19910101" >>> "19910101" "19910101" "19910101" "19910101" >>> >>> dateObs <- as.Date(dates,format="%Y%m%d") >>> dateObs[1:10] >>> [1] "1991-01-01" "1986-01-01" "1991-01-01" "1986-01-01" "1991-01-01" >>> "1991-01-01" "1991-01-01" "1991-01-01" "1991-01-01" "1991-01-01" >>> >>> >>> >>> Now i need to turn the dates into AGE, how do i do it? Im not worried >>> about >>> fractions of years, whole years would do. >>> >>> >>> -- >>> View this message in context: >>> http://old.nabble.com/Turn-dates-into-age-tp26256656p26256656.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. >>> >> >> >> >> -- >> Jim Holtman >> Cincinnati, OH >> +1 513 646 9390 >> >> What is the problem that you are trying to solve? >> >> __ >> 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. >> >> > > -- View this message in context: http://old.nabble.com/Turn-dates-into-age-tp26256656p26257435.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.
Re: [R] Turn dates into age
it sure does thank you! > will this work for you > > x <- c('19910101', '19950302', '20010502') > today <- Sys.Date() > x.date <- as.Date(x, format="%Y%m%d") > round(as.vector(difftime(today , x.date, units='day') / 365.25)) [1] 19 15 9 > On Sun, Nov 8, 2009 at 2:44 PM, wrote: > Hi Jim, > > Thanks for the quick reply...not sure what you mean by frame of > reference(only been using R for 4 days)...to clarify, i need to turn my > dates from 1999-10-01 into 1999 then i subtract 2009 -1999 to get an age > of 10. The column im working on has 312,000 rows and some have NA in them > as we have no dates for that item. > > To recap, the column is just a bunch of dates with some field empty, i > want to change the column from "date of commision" to "age of asset" > > Cheers > Chris. jholtman wrote: > > What is the frame of reference to determine the age? Check out > 'difftime'. > > On Sun, Nov 8, 2009 at 1:50 PM, frenchcr wrote: >> >> Ive got a big column of dates (also some fields dont have a date so they >> have >> NA instead), >> that i have converted into date format as so... >> >> >> dates<-as.character(data[,"date_commissioned"]); # converted dates to >> characters >> dates[1:10] >> [1] "19910101" "19860101" "19910101" "19860101" "19910101" "19910101" >> "19910101" "19910101" "19910101" "19910101" >> >> dateObs <- as.Date(dates,format="%Y%m%d") >> dateObs[1:10] >> [1] "1991-01-01" "1986-01-01" "1991-01-01" "1986-01-01" "1991-01-01" >> "1991-01-01" "1991-01-01" "1991-01-01" "1991-01-01" "1991-01-01" >> >> >> >> Now i need to turn the dates into AGE, how do i do it? Im not worried >> about >> fractions of years, whole years would do. >> >> >> -- >> View this message in context: >> http://old.nabble.com/Turn-dates-into-age-tp26256656p26256656.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. >> > > > > -- > Jim Holtman > Cincinnati, OH > +1 513 646 9390 > > What is the problem that you are trying to solve? > > __ > 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. > > -- View this message in context: http://old.nabble.com/Turn-dates-into-age-tp26256656p26257419.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.
[R] Turn dates into age
Ive got a big column of dates (also some fields dont have a date so they have NA instead), that i have converted into date format as so... dates<-as.character(data[,"date_commissioned"]); # converted dates to characters dates[1:10] [1] "19910101" "19860101" "19910101" "19860101" "19910101" "19910101" "19910101" "19910101" "19910101" "19910101" dateObs <- as.Date(dates,format="%Y%m%d") dateObs[1:10] [1] "1991-01-01" "1986-01-01" "1991-01-01" "1986-01-01" "1991-01-01" "1991-01-01" "1991-01-01" "1991-01-01" "1991-01-01" "1991-01-01" Now i need to turn the dates into years, how do i do it? Im not worried about fractions of years, whole years would do. -- View this message in context: http://old.nabble.com/Turn-dates-into-age-tp26256656p26256656.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.
[R] 19900501 into 1990-05-01
I have a column of dates in this format.. 19900501 I want to change 19900501 into 1990 05 01 then append a new column on the end (right hand side of spreadsheet) :confused: -- View this message in context: http://old.nabble.com/19900501-into-1990-05-01-tp26217515p26217515.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.
[R] enter "missing" into missing fields
if ive got an incomplete data set thats got thousands of rows and 80 columns with random missing fields...like this say... 3 b 3 41 1 x 2 ? how do i turn it into 3b 3 4 missing 1 1x 2 ...i.e., i want to insert a line of text like.."missing"... into the empty fields ? -- View this message in context: http://old.nabble.com/enter-%22missing%22-into-missing-fields-tp26203288p26203288.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.
[R] one long column of data -> three small columns
say i have a column of data like this... 2 3 4 2 1 6 6 4 7 and i want it in three columns like this 226 314 467 ...so i can make a contour plot. How do i do this? -- View this message in context: http://old.nabble.com/one-long-column-of-data--%3E-three-small-columns-tp26163165p26163165.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.
Re: [R] one long column of data -> three small columns
frenchcr wrote: > > say i have a column of data like this... > > 2 > 3 > 4 > 2 > 1 > 6 > 6 > 4 > 7 > > and i want it in three columns like this > > 226 > 314 > 467 > > ...so i can make a contour plot. > > > How do i do this? > ok, so matrix(x, 3, 3) works. what if i have a b c a c a c and want a b c a c a c ?? -- View this message in context: http://old.nabble.com/one-long-column-of-data--%3E-three-small-columns-tp26163165p26163570.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.