Re: [R] Replacing 9999 and 999 values with NA
Just for the record, you do not need cbind(): wind - data.frame(windSpeed,windDirec) Using cbind() does not create a problem as long as the columns are all numeric, but if your data frame contains a mixture of numeric, factor, and character columns, cbind() will mess things up. - David L Carlson Department of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Alexandra Catena Sent: Monday, February 23, 2015 11:50 AM To: Frederic Ntirenganya Cc: r-help@r-project.org Subject: Re: [R] Replacing and 999 values with NA The command, data[data ==] - NA, worked! Thank you! But just in case you wanted to know, I'm downloading the data and unzipping it through readLines. I then concatenate two columns ( wind speed and direction) from the unzipped data through cbind but I make it into a data frame. wind = data.frame(cbind(windSpeed,windDirec)) Thanks, Alexandra On Sat, Feb 21, 2015 at 10:38 PM, Frederic Ntirenganya ntfr...@gmail.com wrote: If you are reading the data frame using for instance read.csv, you can put in the argument na.string =. Another way to do that is data[data ==] - NA. It should be good to tell us how you are reading your dataset. On Feb 21, 2015 6:49 AM, Jeff Newmiller jdnew...@dcn.davis.ca.us wrote: You did not say how you imported the data, but if you used one of the read.table variants (including read.csv) then you can use the na.strings argument as documented in the help file for read.table. Next time please read the posting guide, as there are some useful tips in there, such as posting using plain text (a setting in your email program) so we don't get garbled info from you, and providing a reproducible example. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On February 20, 2015 10:55:30 AM PST, Alexandra Catena amc5...@gmail.com wrote: Hello All, I have a data frame of two columns for wind. The first column is for wind speed and the second wind direction. I'm trying to replace the values in the first column and the 999 values in the second column with NA. I tried to use the function ltdl.fix.df but it doesn't seem to do anything. ltdl.fix.df(windMV, zero2na = FALSE, coded = 999) n = 9432 by p = 4 matrix checked, 0 NA(s) present 0 factor variable(s) present 5675 value(s) coded 999 set to NA 0 -ve value(s) set to +ve half the negative value I have R version 3.1.1 Thanks, Alexandra [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Replacing 9999 and 999 values with NA
Hi, On Monday, February 23, 2015, Alexandra Catena amc5...@gmail.com wrote: The command, data[data ==] - NA, worked! Thank you! But just in case you wanted to know, I'm downloading the data and unzipping it through readLines. I then concatenate two columns ( wind speed and direction) from the unzipped data through cbind but I make it into a data frame. wind = data.frame(cbind(windSpeed,windDirec)) It's better (shorter, more efficient, avoids coercion problems) to omit the cbind(): Wind - data.frame(windSpeed, windDirec) Sarah Thanks, Alexandra On Sat, Feb 21, 2015 at 10:38 PM, Frederic Ntirenganya ntfr...@gmail.com javascript:; wrote: If you are reading the data frame using for instance read.csv, you can put in the argument na.string =. Another way to do that is data[data ==] - NA. It should be good to tell us how you are reading your dataset. On Feb 21, 2015 6:49 AM, Jeff Newmiller jdnew...@dcn.davis.ca.us javascript:; wrote: You did not say how you imported the data, but if you used one of the read.table variants (including read.csv) then you can use the na.strings argument as documented in the help file for read.table. Next time please read the posting guide, as there are some useful tips in there, such as posting using plain text (a setting in your email program) so we don't get garbled info from you, and providing a reproducible example. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.us javascript:;Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On February 20, 2015 10:55:30 AM PST, Alexandra Catena amc5...@gmail.com javascript:; wrote: Hello All, I have a data frame of two columns for wind. The first column is for wind speed and the second wind direction. I'm trying to replace the values in the first column and the 999 values in the second column with NA. I tried to use the function ltdl.fix.df but it doesn't seem to do anything. ltdl.fix.df(windMV, zero2na = FALSE, coded = 999) n = 9432 by p = 4 matrix checked, 0 NA(s) present 0 factor variable(s) present 5675 value(s) coded 999 set to NA 0 -ve value(s) set to +ve half the negative value I have R version 3.1.1 Thanks, Alexandra -- Sarah Goslee http://www.stringpage.com http://www.sarahgoslee.com http://www.functionaldiversity.org [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Replacing 9999 and 999 values with NA
If you are reading the data frame using for instance read.csv, you can put in the argument na.string =. Another way to do that is data[data ==] - NA. It should be good to tell us how you are reading your dataset. On Feb 21, 2015 6:49 AM, Jeff Newmiller jdnew...@dcn.davis.ca.us wrote: You did not say how you imported the data, but if you used one of the read.table variants (including read.csv) then you can use the na.strings argument as documented in the help file for read.table. Next time please read the posting guide, as there are some useful tips in there, such as posting using plain text (a setting in your email program) so we don't get garbled info from you, and providing a reproducible example. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On February 20, 2015 10:55:30 AM PST, Alexandra Catena amc5...@gmail.com wrote: Hello All, I have a data frame of two columns for wind. The first column is for wind speed and the second wind direction. I'm trying to replace the values in the first column and the 999 values in the second column with NA. I tried to use the function ltdl.fix.df but it doesn't seem to do anything. ltdl.fix.df(windMV, zero2na = FALSE, coded = 999) n = 9432 by p = 4 matrix checked, 0 NA(s) present 0 factor variable(s) present 5675 value(s) coded 999 set to NA 0 -ve value(s) set to +ve half the negative value I have R version 3.1.1 Thanks, Alexandra [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Replacing 9999 and 999 values with NA
Hello All, I have a data frame of two columns for wind. The first column is for wind speed and the second wind direction. I'm trying to replace the values in the first column and the 999 values in the second column with NA. I tried to use the function ltdl.fix.df but it doesn't seem to do anything. ltdl.fix.df(windMV, zero2na = FALSE, coded = 999) n = 9432 by p = 4 matrix checked, 0 NA(s) present 0 factor variable(s) present 5675 value(s) coded 999 set to NA 0 -ve value(s) set to +ve half the negative value I have R version 3.1.1 Thanks, Alexandra [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Replacing 9999 and 999 values with NA
You did not say how you imported the data, but if you used one of the read.table variants (including read.csv) then you can use the na.strings argument as documented in the help file for read.table. Next time please read the posting guide, as there are some useful tips in there, such as posting using plain text (a setting in your email program) so we don't get garbled info from you, and providing a reproducible example. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On February 20, 2015 10:55:30 AM PST, Alexandra Catena amc5...@gmail.com wrote: Hello All, I have a data frame of two columns for wind. The first column is for wind speed and the second wind direction. I'm trying to replace the values in the first column and the 999 values in the second column with NA. I tried to use the function ltdl.fix.df but it doesn't seem to do anything. ltdl.fix.df(windMV, zero2na = FALSE, coded = 999) n = 9432 by p = 4 matrix checked, 0 NA(s) present 0 factor variable(s) present 5675 value(s) coded 999 set to NA 0 -ve value(s) set to +ve half the negative value I have R version 3.1.1 Thanks, Alexandra [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.