How to read user input in the console window? [duplicate] - r

I am building an user input interface in R.
onload of the program, I would like like to ask the user what their preferences are according to a set of 6 fields. This will then be used as a comparison tool for the rest of the program.
e.g.,
>ThisProgram
>"Hello, on a scale of 1 to 10, how much would you say you rate the outdoors in your trips? Enter a 10 for very important, and a 1 for not important at all.
>7
>"Great. on a scale of 1 to 10, how much would you say you rate the Family Friendly in your trips? Enter a 10 for very important, and a 1 for not important at all.
>2
.
.
.
and so on...
how would I get R to ask the user a question, and then store the response in a vector?

See ?readline
> x <- readline("What is your name? ")
What is your name? Josh
> x
[1] "Josh"

Related

Error in neighbors[, x] : incorrect number of dimensions when using Predict function for more than 10 rows, recommenderLab in R

I have a data set, Recoset, of ratings given by users for certain product categories. I am trying to learn use the ratings given by users to predict product categories that other users may like by putting the User Based Collaborative Filtering of recommenderLab package to use, in R.
Here is the code
m <- read.csv("recoset2.csv")
rrm <-as(m,"realRatingMatrix")
rrm2 <- rrm[rowCounts(rrm)>5] #only users who have bought from more than 5 verticals (any random 5)
learn <- Recommender(rrm2,method = "UBCF")
learned <- predict(learn,rrm[2001:2010,],n=3)
learned_list <- as(learned,"list")
Now the code works perfectly fine (sometimes) as long as I am predicting for 10 users or less. But the moment I increase the number of users to 11 or more in this manner
learned <- predict(learn,rrm[2001:2020],n=3)
I am greeted by this error
Error in neighbors[, x] : incorrect number of dimensions
This error at times also props up for as low as 2 users, but never have I received this error for 1 user.
I have spent days by myself, gone through the entire recommenderLab documentation, scoured numerous sources & tutorials but debug this error. Any help in resolving this would be immensely appreciated
> user item rating
> ORG1SNQ0TV16NQP6ZB5SD9XGX1FP7 MobileCable 2
> ORG441VE999BMCTYGZ0H7HDWHGX62 OTGPendrive 2
> ORG7L1NRFQZTPDJRFXC0CQ1LXLY6E MobileScreenGuard 3
> ORGBYFYMG92YFDC043NG7PZEHEPTS MobileScreenGuard 2
> ORGLZH07SFPSFQ3RZJMCV85XKKDKE Smartphone 5
> ORGMBN2841ZDJDZD4HHEN28HB5YYP Headphone 1
Here is the link to the dataset
I know it's probably not a whole lot of help: but I found using Item Based Collaborative filtering circumvents this issue. I found an example here which returned the same error:
https://rpubs.com/dhairavc/639597
I think it has something to do with the number of neighbours for UBCF.
If you change the line to:
learn <- Recommender(rrm2,method = "IBCF")
I imagine you will likely return a result. User-based isn't a friendly towards sparce matricies.
I hope this helps, I'll update you if I get any closer to a fix!
Change the Recommendation line with different methods
learn <- Recommender(rrm2,method = "IBCF") # Change with "UBCF","SVD","POPULAR"

Drupal Webform : set SCORE on each SELECT Options?

I have webforms on drupal with multiple select options (radio).
And in my select, I want to say option 1 : gives 2 points, option 2 : give 1 point, etc... For after display on a webpage : your score is 12/20 points.
example :
A bear can be ... ?
0|White <- response give 2 points
1|Yellow <- response give 0 point
2|Brown <- response give 2 points
3|Dark <- response give 1 points
The question is : how to store the point of select options because there is only key|value in the admin interface?
In fact : how to add infos each select option row?
The way to do this would be to associate key with points. Thus 0 corresponds to 2 points, 1 to 0 point, 2 to 2 points and 3 to 1 point.
Thus on submission you would look at user responses and then calculate based on the responses to those particular question.
Thus under form settings would set the redirection location to a page where you process this logic and then redirect from there or show the output on the same page.
Finally, that I do :
I fill the option list with :
key_score|description
And i use explode function with _ seprator.

SAS Enterprise Guide Count IF

I'm looking to be able to perform the equivalent of a count if on a data set similar to the below. I found something similar here, but I'm not sure how to translate it into Enterprise Guide. I would like to create several new columns that count how many date occurrences there are for each primary key by year, so for example:
PrimKey Date
1 5/4/2014
2 3/1/2013
1 10/1/2014
3 9/10/2014
To be this:
PrimKey 2014 2013
1 2 0
2 0 1
3 1 0
I was hoping to use the advanced expression for calculated fields option in query builder, but if there is another better way I am completely open.
Here is what I tried (and failed):
CASE
WHEN Date(t1.DATE) BETWEEN Date(1/1/2014) and Date(12/31/2014)
THEN (COUNT(t1.DATE))
END
But that ended up just counting the total date occurrences without regard to my between statement.
Assuming you're using Query Builder you can use something like the following:
I don't think you need the CASE statement, instead use the YEAR() function to calculate the year and test if it's equal to 2014/2013. The test for equality will return a 1/0 which can be summed to the total per group. Make sure to include PrimKey in your GROUP BY section of query builder.
sum(year(t1.date)=2014) as Y2014,
sum(year(t2.date)=2013) as Y2013,
I don't like this type of solution because it's not dynamic, i.e. if your years change you have to change your code, and there's nothing in the code to return an error if that happens either. A better solution is to do a Summary Task by Year/PrimKey and then use a Transpose Task to get the data in the structure you want it.

How to read /manipulate input in ADA?

Reading from standard input, I want to be able to insert a few sets of integers like so and do some math on every 2 integers.
I.E:
"Hello enter some numbers to get their sum":
1 9
2 10 [enter]
OUTPUT:
1 + 9 = 10.
2 + 10 = 12.
I have been successful with only the user being able to enter only 2 integers as I just do
get(numOne);
get(numTwo);
and then something like:
answer := numOne + numTwo;
put_line(answer'img);
But I am new to ADA and don't know how I can scan through all four of the integers I used in my example and only sum the first two then the second two, and if there is more then keep summing them up by two's. Essentially the program would first scan through all the user input and do math on every two integers and keep concatenating them to a result string that we can print at the end. I know how to do it, I am just new to the language and don't how to put it in code. Please ask if you need more info. All help is appreciated.
Just put a loop around your existing logic. - And notice that Ada has nice "infinite" loops. :-)

Restart list numbering in word for each new list created

I am exporting content from a jsp page into MS Word using javascript.
When the user is in Word there is a table with 10 rows and 2 columns, A & B. The user creates an ordered list in row 1, column A like this:
1 dog
2 cat
3 mouse
if the user then creates a second list in row 1 column B is turns out like this:
4 car
5 truck
6 bike
instead of:
1 car
2 truck
3 bike
Word is set up to continue the numbering in lists from prior lists automatically. I know this can be reset easily but the users dont want to have to do this. They want the numbering of any potential lists created to restarted at 1. when the document is exported into Word and opened in front of them.
So this must be set up in the javasctipt code or using a style or something prior to getting into Word. This is what I dont know how to do.
Any help is much appreciated.
Thanks,
Feena.
If you use a named sequence rather than the in-built lists (as in inserting an instnace of the field {SEQ SequenceName} everywhere you want a number), and choose a different name for each of the different lists, it will work as you desire.
e.g.
{SEQ OpenIssueSeq} Issue 1
(SEQ OpenIssueSeq} Issue 2
etc.

Resources