r

R largest/smallest representable numbers

a 夏天 提交于 2021-02-18 09:56:05
问题 I'm trying to get the largest/smallest representable number in R. After typing ".Machine" I got: $double.xmin [1] 2.225074e-308 $double.xmax [1] 1.797693e+308 However even if I type 2.225074e-309 in R command prompt I get 2.225074e-309 instead of the expected 0 How can I find the largest/smallest number for which adding or subtracting 1 would lead to either Inf(Adding 1 to largest number) or 0(subtracting 1 from smallest number) ? 回答1: .Machine$double.xmin gives the value of the smallest

Optimizing (minimizing) the number of lines in file: an optimization problem in line with permutations and agenda scheduling

旧巷老猫 提交于 2021-02-18 09:55:12
问题 I have a calendar, typically a csv file containing a number of lines. Each line corresponds to an individual and is a sequence of consecutive values '0' and '1' where '0' refers to an empty time slot and '1' to an occupied slot. There cannot be two separated sequences in a line ( e.g. two sequences of '1' separated by a '0' such as '1,1,1,0,1,1,1,1'). The problem is to minimize the number of lines by combining the individuals and resolving the collisions between time slots. Note the time

R: Launch web browser

只愿长相守 提交于 2021-02-18 09:54:29
问题 Is there a way to launch internet explorer with a given URL in R? I want to scrape web pages in order to extract certain values, but I want to open the web pages themselves just so I can step through each one to make sure the data seems right. 回答1: Here you go: browseURL("http://www.r-project.org") If you need it, browseURL() also takes an argument browser= that lets you specify the name or path of the program to be used as a browser. 回答2: Maybe something like: system("iexplore.exe http://www

Ifelse statement in R with multiple conditions

耗尽温柔 提交于 2021-02-18 09:28:08
问题 With the following sample data I'm trying to create a new variable "Den" (value "0" or "1") based on the values of three conditional variables (Denial1, Denial2, and Denial3). I want a "0" if ANY of the three conditional variables has a "0" and a "1" only if EACH conditional variable that has a value in it has a value of "1" (e.g., isn't NA). structure(list(Denial1 = NA_real_, Denial2 = 1, Denial3 = NA_real_, Den = NA), .Names = c("Denial1", "Denial2", "Denial3", "Den" ), row.names = 1L,

Get ggplot2 legend to display percentage sign in r

孤者浪人 提交于 2021-02-18 09:10:28
问题 Below is a reproducible example of the issue I am trying to solve. I have created a heatmap of sorts in ggplot2 and things have been going well. Since I have put percentage signs on the data to use with geom_text I would like to make the legend of geom_tile also to display percent signs (I can only multiply the actual values by 100 right now). Ideally I would like the legend bar on the right to show 8%, 4%, 0%, -4%, -8%. #load in libraries require(plyr) require(dplyr) require(reshape2)

Get ggplot2 legend to display percentage sign in r

青春壹個敷衍的年華 提交于 2021-02-18 09:09:13
问题 Below is a reproducible example of the issue I am trying to solve. I have created a heatmap of sorts in ggplot2 and things have been going well. Since I have put percentage signs on the data to use with geom_text I would like to make the legend of geom_tile also to display percent signs (I can only multiply the actual values by 100 right now). Ideally I would like the legend bar on the right to show 8%, 4%, 0%, -4%, -8%. #load in libraries require(plyr) require(dplyr) require(reshape2)

Obtaining random-effects matrices from a mixed model

↘锁芯ラ 提交于 2021-02-18 08:43:31
问题 In my below code, I was wondering how I can obtain the equivalent of out and Ts from an lme() object in the library(nlme) ? dat <- read.csv("https://raw.githubusercontent.com/rnorouzian/v/main/mv.l.csv") library(lme4) x <- lmer(value ~0 + name+ (1| School/Student), data = dat, control = lmerControl(check.nobs.vs.nRE= "ignore")) lwr <- getME(x, "lower") theta <- getME(x, "theta") out = any(theta[lwr == 0] < 1e-4) # find this from `x1` object below Ts = getME(x, "Tlist") # find this from `x1`

Obtaining random-effects matrices from a mixed model

被刻印的时光 ゝ 提交于 2021-02-18 08:42:23
问题 In my below code, I was wondering how I can obtain the equivalent of out and Ts from an lme() object in the library(nlme) ? dat <- read.csv("https://raw.githubusercontent.com/rnorouzian/v/main/mv.l.csv") library(lme4) x <- lmer(value ~0 + name+ (1| School/Student), data = dat, control = lmerControl(check.nobs.vs.nRE= "ignore")) lwr <- getME(x, "lower") theta <- getME(x, "theta") out = any(theta[lwr == 0] < 1e-4) # find this from `x1` object below Ts = getME(x, "Tlist") # find this from `x1`

combine two looping structures to obtain a matrix output

怎甘沉沦 提交于 2021-02-18 08:38:49
问题 I'm using two closely related formulas in R. I was wondering if it might be possible to combine B1 and B2 to get my desired matrix output shown below? z <- "group y1 y2 1 1 2 3 2 1 3 4 3 1 5 4 4 1 2 5 5 2 4 8 6 2 5 6 7 2 6 7 8 3 7 6 9 3 8 7 10 3 10 8 11 3 9 5 12 3 7 6" dat <- read.table(text = z, header = T) (B1 = Reduce("+", group_split(dat, group, .keep = FALSE) %>% map(~ nrow(.)*(colMeans(.)-colMeans(dat[-1]))^2))) # y1 y2 #61.86667 19.05000 (B2 = Reduce("+",group_split(dat, group, .keep =

How to import an .R file and assign an alias to it? Like import myfile.R as mf

心不动则不痛 提交于 2021-02-18 08:17:32
问题 R beginner here, who really misses Python's import pandas as pd import my_file_which_is_just_a_file_not_a_package as mf out = mf.my_cool_function() I have found a way to implement something similar to the former (assigning an alias to a package), but how to do the latter, i.e. how to assign an alias to an .R file (not a package) you are importing? E.g. you have put some functions you use frequently into a separate .R file, or you are dividing your program into multiple .R files to keep things