r-faq

How can I subset rows in a data frame in R based on a vector of values?

蹲街弑〆低调 提交于 2019-12-17 07:09:27
问题 I have two data sets that are supposed to be the same size but aren't. I need to trim the values from A that are not in B and vice versa in order to eliminate noise from a graph that's going into a report. (Don't worry, this data isn't being permanently deleted!) I have read the following: Selecting columns in R data frame based on those *not* in a vector http://www.ats.ucla.edu/stat/r/faq/subset_R.htm How to combine multiple conditions to subset a data-frame using "OR"? But I'm still not

How can I subset rows in a data frame in R based on a vector of values?

纵然是瞬间 提交于 2019-12-17 07:09:00
问题 I have two data sets that are supposed to be the same size but aren't. I need to trim the values from A that are not in B and vice versa in order to eliminate noise from a graph that's going into a report. (Don't worry, this data isn't being permanently deleted!) I have read the following: Selecting columns in R data frame based on those *not* in a vector http://www.ats.ucla.edu/stat/r/faq/subset_R.htm How to combine multiple conditions to subset a data-frame using "OR"? But I'm still not

What do the %op% operators in mean? For example “%in%”?

亡梦爱人 提交于 2019-12-17 07:07:15
问题 I tried to do this simple search but couldn't find anything on the percent ( % ) symbol in R. What does %in% mean in the following code? time(x) %in% time(y) where x and y are matrices. How do I look up help on %in% and similar functions that follow the %stuff% pattern, as I cannot locate the help file? Related questions: What does eg %+% do? in R The R %*% operator What does %*% mean in R What does %||% do in R? What does %>% mean in R 回答1: Put quotes around it to find the help page. Either

Display exact value of a variable in R

妖精的绣舞 提交于 2019-12-17 06:56:08
问题 > x <- 1.00042589212565 > x [1] 1.000426 If I wanted to print the exact value of x , how would I do it? Sorry if this is a dumb question. I tried Googling for "R" and "exact" or "round" but all I get are articles about how to round. Thank you in advance! 回答1: Globally solution during all the session options(digits=16) > x [1] 1.00042589212565 or locally just for x: sprintf("%.16f", x) [1] "1.0004258921256499" 回答2: print(x, digits=15) or format(x, digits=15) or sprintf("%.14f", x) 来源: https:/

How to find all functions in an R package?

≡放荡痞女 提交于 2019-12-17 06:09:43
问题 What is the best way to find all the functions associated in a package?? I am currently going through the caTools package. If I do ?caTools or ??caTools I am simply going to get search for functions called that but not the functions in the package. Is there an easy way to access all the functions in the R gui? Are there any good ways to search for functions? 回答1: I am guessing that you are just looking for help(package = caTools) , which will open your browser to the relevant help page that

Set default CRAN mirror permanent in R

我只是一个虾纸丫 提交于 2019-12-17 05:53:23
问题 How can I set a specific CRAN mirror permanently in R? I want to set it permanently in my laptop so that when I do install.packages() , it won't ask me again which mirror to choose. 回答1: You can set repos in your .Rprofile to restore your choice every time you start R Edit: to be more precise: Add options(repos=structure(c(CRAN="YOUR FAVORITE MIRROR"))) to your .Rprofile Alternatively, you can set the mirror site-wide in your Rprofile.site . The location of the file is given by ?Startup : The

Set default CRAN mirror permanent in R

﹥>﹥吖頭↗ 提交于 2019-12-17 05:52:10
问题 How can I set a specific CRAN mirror permanently in R? I want to set it permanently in my laptop so that when I do install.packages() , it won't ask me again which mirror to choose. 回答1: You can set repos in your .Rprofile to restore your choice every time you start R Edit: to be more precise: Add options(repos=structure(c(CRAN="YOUR FAVORITE MIRROR"))) to your .Rprofile Alternatively, you can set the mirror site-wide in your Rprofile.site . The location of the file is given by ?Startup : The

Remove backslashes from character string

混江龙づ霸主 提交于 2019-12-17 05:15:36
问题 I am reading text in from a txt file and pass the contents to SQL. The SQL text contains double quotes and is causing problems. I would like to remove the "\" in the string below so I can send it to SQL test<- "select case when \"est\" dsaf" test<- cat(test, sep="") class(test) returns an UNQUOTED null object > test<- "select case when \"est\" dsaf" > test<- cat(test, sep="") select case when "est" dsaf > class(test) [1] "NULL" When I pass the unquoted string to SQL I get this error: Error in

Remove backslashes from character string

不想你离开。 提交于 2019-12-17 05:15:04
问题 I am reading text in from a txt file and pass the contents to SQL. The SQL text contains double quotes and is causing problems. I would like to remove the "\" in the string below so I can send it to SQL test<- "select case when \"est\" dsaf" test<- cat(test, sep="") class(test) returns an UNQUOTED null object > test<- "select case when \"est\" dsaf" > test<- cat(test, sep="") select case when "est" dsaf > class(test) [1] "NULL" When I pass the unquoted string to SQL I get this error: Error in

Variable name restrictions in R

梦想与她 提交于 2019-12-17 05:03:43
问题 What are the restrictions as to what characters (and maybe other restrictions) can be used for a variable name in R? (This screams of general reference, but I can't seem to find the answer) 回答1: You might be looking for the discussion from ?make.names : A syntactically valid name consists of letters, numbers and the dot or underline characters and starts with a letter or the dot not followed by a number. Names such as ".2way" are not valid, and neither are the reserved words. In the help file