Skip to main content

Posts

Converting categorical variables into numbers

I have a categorical variable educa that needs to be converted into numbers for readability. educa can take on 6 values. I want to convert them into 1-6. How do I do this? This doesn't work: brfs2013educationsummarycleaned % mutate( educa_level = ifelse(educa == "Never attended school or only kindergarten", 1, educat == "Grades 1 through 8 (Elementary)", 2, "not a real category")) What am I doing wrong? The above is a portion of what I intend to do. Solved We can use match if the values in 'educa' have to be converted based on the order in which they appear in the data library(tidyverse) brfs2013educationsummary %>% mutate(educa_level = match(educa, unique(educa))) as.numeric(educa) will do what you want and if you want it as new column brfs2013educationsummarycleaned % mutate(educa_level = as.numeric(educa))
Recent posts

Fade Inline-Block with CSS and Velocity JS

I'm using Velocity JS to fade a list object. The problem is that Velocity applies display: list-item; opacity: 1; to the element and overrides my display: inline-block; and my list is now vertical. How can I force it to always use inline-block? https://jsfiddle.net/01qvqmxa/ HTML test test test CSS li { opacity: 0; display: inline-block; padding: 1em; } JS $(".myList li").velocity("fadeIn", { delay: 300, duration: 2000 }); Solved Try using the !important notation: li { opacity: 0; display: inline-block !important; padding: 1em; } revised fiddle

Users/Classroom Associations

I'm a fairly new to rails, and I'm trying to create an app where users can own many classrooms, and classrooms can have many users. I'm not sure how to set up the models, however. Let’s say I have a teacher named Joe. Joe has many classrooms. Each of Joe’s classrooms can have many students, so from those many classrooms Joe also has many students. But I also want Joe to be able to be part of a classroom as a student, and I want students to be able to create their own classrooms, as teachers, from the same account. Classrooms should also be able to have more than one teacher. I also want to be able to do something like user.classrooms.first.users, where user is Joe, and users are his students in his first classroom. What models should I create, and how would I set up the associations? I was thinking has_and_belongs_to_many , but apparently it's not preferred anymore, and has_many :through would be better. What it's looking like to me is something like:...

Is there a way to replace built-in Models Endpoint method in loopbackjs?

I am trying to replace the User model's built-in Create method to add some extra custom logic and reformat the response data according to my need. Is there any way to do it? Thanks in advance Solved You need to declare a new model. Then, afterwards, manually add a base property for it to inherit from the built-in User model. /common/models/custom-user.json { "name": "customUser", "base": "User", "options": { "idInjection": false, "postgresql": { "schema": "public", "table": "user" } }, "dataSource": "mypostgresDS", "properties": { "id": { "type": "number", "postgresql": { "columnName": "id", "dataType": "integer" } } ... ... } } Then you can override builtin rout...