Why does data get altered while applying a function [closed] - r

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I loaded a RDS file. The file contains a numeric field. When I say
class(NEI$Emissions)
it returns
"numeric"
The data is in maximum 3 digits and contains 3 digits of decimal. However, when I issue the command
max(NEI$Emissions)
it returns a huge number.
646952
How can I use the numeric values as it is?

R doesn't lie. One of your data points is not what you expect.
Find which row has the problem with this command:
which.max(NEI$Emissions)
then examine that row of your original data. You will find the errant value.

Related

How to extract x matrix from the R output? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 13 days ago.
Improve this question
I run my program written as a function. In that function, variable x is updated several times due to optimization. Finally, it gives the output of the matrix x and the value of convergence. How can I extract the value of x and have it to insert into another program?
First, I run the function, then I put a value in place of the input of the function, and finally it outputs the value of the matrix x. But I can't extract it to use in another program.
The x matrix in the output is $x. But when I write in the console x gives an error.
enter image description here

Value entered twice in one vector [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a column with a range 1:5. Many vectors contain the value twice, for example (33) instead of (3) and (11) instead of 1. Is there any code to delete these duplicates and keep one number within a vector?
Thanks a lot
Say your column is named y:
substr(y,1,1)
Takes from the first digit to the first digit (i.e. only the first) of y (element-wise). But substr outputs a character, to transform it back to numeric:
as.numeric(substr(y,1,1))

How come I am able to pass a dataframe into 'dparams' argument in 'geom_qq' function, when it is specified as a 'list' type argument? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
How come I am able to pass a dataframe into the dparams argument of the geom_qq() function, when it is specified as a list type argument?
Is it because a dataframe is technically a list of equal length vectors?
I would say so. A data frame can in general be treated like a list, not necessarily the other way around though.
Without knowing your data, your general idea is correct.
See also:
http://www.r-tutor.com/r-introduction/data-frame

In R, find value in one CSV, isolate it in another [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm working on a project in R, regarding baseball. I have two CSV's that I'm working with. One file, CSV2: "PitchingPost.csv" is all postseason pitching stats, and the column I'm looking at there is the "teamID". I'm trying to evaluate regular season pitching stats in another file, CSV1: "pitching.csv" but only for teams that made the postseason. So I'm trying to remove all of the items in the "teamID" of CSV1 EXCEPT for those occur in CSV2 "teamID".
Help?
To keep only the rows from your first file that share an ID with rows in your second file, you could try something like that:
pitch <- read.csv("pitching.csv")
pitch_post <- read.csv("PitchingPost.csv")
pitch <- pitch[pitch$teamID %in% unique(pitch_post$teamID),]

Advanced subsetting r data frame [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Without using a special function, can you do the following to change the values in an R dataframe from a column that have length greater than 4:
df[length(df$Column1)>4,"Column1"] = "replacement value"
This does not seem to work, is there an alternative index style I can use, or do I need to use a function?
Thanks
The function to determine the length of an entry, like a word in a dataframe, is nchar(), and not length(). The latter is typically used to determine the number of entries in a vector.
You could therefore try using:
df[nchar(df$Column1) > 4, "Column1"] <- "replacement value"

Resources