Error with apply function

I have a dtl table and a lookup table (GLMap) dtl: Lookup Table (GLAcctMap): Expected Output: DEAL_TYPE DN_DIRECTION key COMPANY_CODE GLAccount GLACCT POWER S 1 AFFL_CO 1702 1702 POWER P 2 AFFL_CO 3702 3702 MISC S 3 AFFL_CO 5717 5717 MISC P 4 AFFL_CO 5718 5718 POWER S 5 AFFL_CO 1702 1702 POWER S 6 … Read more

Categories R

Understanding `scale` in R

log simply takes the logarithm (base e, by default) of each element of the vector.scale, with default settings, will calculate the mean and standard deviation of the entire vector, then “scale” each element by those values by subtracting the mean and dividing by the sd. (If you use scale(x, scale=FALSE), it will only subtract the mean but not … Read more

Categories R

Subscript out of bounds – general definition and solution?

This is because you try to access an array out of its boundary. I will show you how you can debug such errors. I set options(error=recover) I run reach_full_in <- reachability(krack_full, ‘in’) I get :reach_full_in <- reachability(krack_full, ‘in’) Error in reach_mat[i, alter] = 1 : subscript out of bounds Enter a frame number, or 0 to exit 1: … Read more

Categories R

Custom legend for multiple layer ggplot

Instead of setting colour and fill, map them using the geometry aesthetics aes and then use scale_xxx_manual or scale_xxx_identity. Eg Note that you must specify guide = ‘legend’ to force scale_…_identity to produce a legend. scale_…manual you can pass a named vector for the values — the names should be what you called the colours within the calls to geom_… and then you can label nicely.

Categories R

Having trouble setting working directory

The command setwd(“~/”) should set your working directory to your home directory. You might be experiencing problems because the OS you are using does not recognise “~/” as your home directory: this might be because of the OS, or it might be because of not having set that as your home directory elsewhere. As you have tagged the post … Read more

Categories R

How to convert a factor to integer\numeric without loss of information?

See the Warning section of ?factor: In particular, as.numeric applied to a factor is meaningless, and may happen by implicit coercion. To transform a factor f to approximately its original numeric values, as.numeric(levels(f))[f] is recommended and slightly more efficient than as.numeric(as.character(f)). The FAQ on R has similar advice. Why is as.numeric(levels(f))[f] more efficent than as.numeric(as.character(f))? as.numeric(as.character(f)) is effectively as.numeric(levels(f)[f]), so you are performing the conversion to numeric on length(x) values, rather … Read more

Categories R

Remove rows with all or some NAs (missing values) in data.frame

Also check complete.cases : na.omit is nicer for just removing all NA‘s. complete.cases allows partial selection by including only certain columns of the dataframe: Your solution can’t work. If you insist on using is.na, then you have to do something like: but using complete.cases is quite a lot more clear, and faster.

Categories R

What is the difference between rm() and rm(list=ls())?

Most of articles, I have read. They recommend to use rm(list=ls()) but I do not know what is the difference if I like to use rm() Can I use rm() instead of rm(list=ls()) if i would like to clear all variables? Please give me some advices. Thanks.

Categories R