factors

R scatter plot with hexadecimal colors

大憨熊 提交于 2020-01-04 04:13:08
问题 I've got a CSV file with 3 columns, the X values, Y values, and their corresponding hexadecimal (#RRGGBB) values. I've been trying to create a scatter/bubble plot with the insides of the bubbles colored according to the hex values. symbols(year, logtrans, circles=size, inches=0.05, bg=intel2$HexLogClock) intel2$HexLogClock contains the hex values. Sorry again for the noob question, any help is appreciated. 回答1: I think your trouble may lie in the hex values not being a character. Make sure

Setting levels when creating a factor vs. `levels()<-`

醉酒当歌 提交于 2020-01-01 05:05:25
问题 Let's create some factors first: F1 <- factor(c(1,2,20,10,25,3)) F2 <- factor(paste0(F1, " years")) F3 <- F2 levels(F3) <- paste0(sort(F1), " years") F4 <- factor(paste0(F1, " years"), levels=paste0(sort(F1), " years")) then take a look at them: > F1 [1] 1 2 20 10 25 3 Levels: 1 2 3 10 20 25 > F2 [1] 1 years 2 years 20 years 10 years 25 years 3 years Levels: 1 years 10 years 2 years 20 years 25 years 3 years > F3 [1] 1 years 3 years 10 years 2 years 20 years 25 years Levels: 1 years 2 years 3

Print all unique combination of factors of a given number

守給你的承諾、 提交于 2020-01-01 02:25:29
问题 What is the most efficient algorithm to print all unique combinations of factors of a positive integer. For example if the given number is 24 then the output should be 24*1 12*2 8*3 6*4 6*2*2 4*3*2 3*2*2*2 Here notice that when 6*4 gets printed then 4*6 doesn't get printed. So basically it's a problem of taking unique subsets without considering the order (one way to look at the problem). But the objective is to have a function that runs the fastest, so storing the factors in a data structure

Is there any good reason for columns to be characters instead of factors?

做~自己de王妃 提交于 2019-12-23 15:12:50
问题 This mind seem like a silly question, but after working with R for a couple of months I realised I often find myself converting strings to factors as, for example, the tabulate function does not work on strings. At this point I am contemplating simply always converting any string to a factor. But that begs the question, is there any reason not to (apart from carrying out operations on the string itself)? 回答1: Factors have a dual representation -- the 'label'; and underlying encoding of the

Aggregate with max and factors

ε祈祈猫儿з 提交于 2019-12-22 08:44:14
问题 I have a data.frame with columns of factors, on which I want to compute a max (or min, or quantiles). I can't use these functions on factors, but I want to. Here's some example : set.seed(3) df1 <- data.frame(id = rep(1:5,each=2),height=sample(c("low","medium","high"),size = 10,replace=TRUE)) df1$height <- factor(df1$height,c("low","medium","high")) df1$height_num <- as.numeric(df1$height) # > df1 # id height height_num # 1 1 low 1 # 2 1 high 3 # 3 2 medium 2 # 4 2 low 1 # 5 3 medium 2 # 6 3

Why is my Swift loop failing with error “Can't form range with end < start”?

拜拜、爱过 提交于 2019-12-20 17:36:43
问题 I have a for loop that checks if a number is a factor of a number, then checks if that factor is prime, and then it adds it to an array. Depending on the original number, I will get an error saying fatal error: Can't form range with end < start This happens almost every time, but for some numbers it works fine. The only numbers I have found to work with it are 9, 15, and 25. Here is the code: let num = 16 // or any Int var primes = [Int]() for i in 2...(num/2) { if ((num % i) == 0) { var

Identifying or coding unique factors

佐手、 提交于 2019-12-17 21:14:41
问题 I would like to create a new variable,litter, to indicate each sow or litter in different farrowing dates (fdate). Each litter is to be numbered from 1 to N with an increament of 1 as shown in the last column. sow season piglet fdate litter 1M521 1 5702 14/09/2009 1 1M521 1 5703 14/09/2009 1 1M521 2 22920 17/02/2010 2 1M521 2 22920 17/02/2010 2 1M521 2 22920 17/02/2010 2 1M584 1 8516 28/09/2009 3 1M584 1 8516 28/09/2009 3 1M584 1 8516 28/09/2009 3 1N312 1 6192 16/09/2009 4 1N312 1 6193 16/09

How can I ensure that a partition has representative observations from each level of a factor?

放肆的年华 提交于 2019-12-17 19:26:00
问题 I wrote a small function to partition my dataset into training and testing sets. However, I am running into trouble when dealing with factor variables. In the model validation phase of my code, I get an error if the model was built on a dataset that doesn't have representation from each level of a factor. How can I fix this partition() function to include at least one observation from every level of a factor variable? test.df <- data.frame(a = sample(c(0,1),100, rep = T), b = factor(sample

R * not meaningful for factors ERROR

非 Y 不嫁゛ 提交于 2019-12-17 09:51:57
问题 I have the following data.frame and I want to perform some calculations on the 2nd column. > test code age 1 101 15 2 102 25 3 103 16 4 104 u1 5 105 u1 6 106 u2 7 107 27 8 108 27 As you can see, the 2nd column does not include only numbers. I omitted these cases: > new<-subset(test,code<104 | code>106) > new code age 1 101 15 2 102 25 3 103 16 7 107 27 8 108 27 But when I try to do a calculation in a new column this is what I get: > new["MY_NEW_COLUMN"] <- NA > new code age MY_NEW_COLUMN 1

Finding largest prime number out of 600851475143?

六月ゝ 毕业季﹏ 提交于 2019-12-17 03:19:27
问题 I'm trying to solve problem 3 from http://projecteuler.net. However, when I run thing program nothing prints out. What am I doing wrong? Problem: What is the largest prime factor of the number 600851475143 ? public class project_3 { public boolean prime(long x) // if x is prime return true { boolean bool = false; for(long count=1L; count<x; count++) { if( x%count==0 ) { bool = false; break; } else { bool = true; } } return bool; } public static void main(String[] args) { long ultprime = 0L; /