Is there a way to integrate macros with google forms? - google-forms

I have a basic google form with a short answer input. I'd like to split the input of the form by commas so text input like
aaa, bbb, ccc
would appear in the spreadsheet as
I've tried adding the following macro to column C
=ArrayFormula(split(B1:B500, ","))
but the problem is that new form submissions will just create a new row without the macro applied to columns C, D, E, etc. Is there a way to ensure the macro gets applied to new rows created from users submitting the google form?

It seems like the solution was to change the macro formula from
=ArrayFormula(split(B1:B500, ","))
to
=ArrayFormula(split(B1, ","))
then manually drag the formula down as many rows as needed. Not really sure why this was the case.

Related

Autocoding using RQDA

I try to use RQDA for quantitative text analysis. I want to code text passages with the same characters automatically.
Let´s say I have the category dog and I marked "dog" in the first sentence and "dogfood" in the fourth. I want RQDA mark "dog" also in the second sentence and "dogfood in the fifth.
In Maxqda, for example, this is done automatically if I enable the software. Is there a function to do this?
If I understand you want to make an automatic coding using RQDA. The function would be codingBySearch:
codingBySearch(pattern, fid = getFileIds(), cid, seperator,
concatenate = FALSE)
But this function only allows you to make a single pattern per time. If you would like to get a list of patterns, a loop will sort it out:
X <- c("pattern1", "pattern2", "pattern3", "pattern4", "pattern5", "pattern6")
for (i in X) {
codingBySearch(i,fid=getFileIds(),cid=cid_number, seperator="[.!?]",ignore.case=TRUE)
}
Where cid is the number of the code you created in the GUID interface. You can also adapt the separators as you see fit.

Combining many vectors into one larger vector (in an automated way)

I have a list of identifiers as follows:
url_num <- c('85054655', '85023543', '85001177', '84988480', '84978776', '84952756', '84940316', '84916976', '84901819', '84884081', '84862066', '84848942', '84820189', '84814935', '84808144')
And from each of these I'm creating a unique variable:
for (id in url_num){
assign(paste('test_', id, sep = ""), FUNCTION GOES HERE)
}
This leaves me with my variables which are:
test_8505465, test_85023543, etc, etc
Each of them hold the correct output from the function (I've checked), however my next step is to combine them into one big vector which holds all of these created variables as a seperate element in the vector. This is easy enough via:
c(test_85054655,test_85023543,test_85001177,test_84988480,test_84978776,test_84952756,test_84940316,test_84916976,test_84901819,test_84884081,test_84862066,test_84848942,test_84820189,test_84814935,test_84808144)
However, as I update the original 'url_num' vector with new identifiers, I'd also have to come down to the above chunk and update this too!
Surely there's a more automated way I can setup the above chunk?
Maybe some sort of concat() function in the original for-loop which just adds each created variable straight into an empty vector right then and there?
So far I've just been trying to list all the variable names and somehow get the output to be in an acceptable format to get thrown straight into the c() function.
for (id in url_num){
cat(as.name(paste('test_', id, ",", sep = "")))
}
...which results in:
test_85054655,test_85023543,test_85001177,test_84988480,test_84978776,test_84952756,test_84940316,test_84916976,test_84901819,test_84884081,test_84862066,test_84848942,test_84820189,test_84814935,test_84808144,
This is close to the output I'm looking for but because it's using the cat() function it's essentially a print statement and its output can't really get put anywhere. Not to mention I feel like this method I've attempted is wrong to begin with and there must be something simpler I'm missing.
Thanks in advance for any help you guys can give me!
Troy

Equivalent in Octave / Matlab for R head() and tail() functions

What are the equivalent ways to calling the beginning (or ending) of a data set in Octave / MATLAB?
These are incredibly useful functions to avoid printing out the entire dataset on the console, and get an idea of the headings and type of data.
It would be great to also have an equivalent for str() along the same lines...
There is no built-in but you can easily grab the first N rows or the last M rows.
A = rand(10000, 2);
% First 10 rows
A(1:10, :)
% Last 10 columns
A((end-9):end,:)
The same will work if you are using a table to store your data.
t = table(rand(10000,1), rand(10000,1));
t(1:10,:)
t((end-9):end,:)
Or a dataset
d = dataset(rand(10000,1), rand(10000,1))
d(1:10,:)
d((end-9):end,:)
You could easily create the following head() and tail() anonymous functions which you could use to do this easily.
tail = #(data)disp(data(max(size(data, 1)-9, 1):end,:));
head = #(data)disp(data(1:min(10, size(data,1)),:));
And use them like a normal function
head(d)
Variables editor can be useful for quickly inspecting your data. There's also a handy keyboard shortcut to open your variable in the editor - select the variable name (either in editor or in command window) and press ctrl+D. It also displays structure arrays quite nicely - often that's much easier than inspecting through command window.

Basic Apply in R dataframe (possible for loops as well)

I'm trying to do some work on a basic dataframe, you can see it below:
> print(thisEmailList)
user_name user_email
1 Test, Joe joejoejt#gmeel.com
2 adminintor, Admin jimmyadminj#gmeel.com
I would like to send some emails to these folks, but I am unsure what is the best approach. I have a function, sendmail, that seems to work fine with strings, but how do I iterate or apply this function to my dataframe?
I've tried many different tacts, for loops, and functions in lapply, but I cannot seem to get it to appear in the same way the database puts it out. I always seem get something to this effect:
user_name
1 Test, Joe
2 adminintor, Admin
user_email
1 joejoejt#gmeel.com
2 jimmyadminj#gmeel.com
I am thinking of thisEmailList as rows and columns, and I would like to loop through the rows, not the columns. R has been quite the difference in how to think, and I am just not getting the syntax, or how I go about sending an email to each row in the above.
Update 1
I think I finally figured it out, for a forloop anyway. If anyone has a suggestion that doesn't involved a for loop, that would be fantastic.
for (i in 1:nrow(thisEmailList)){
#Note this is just for testing, the sendmailr part has never been an issue, just getting the row/columns to loop in the right order.
print(paste(thisEmailList[i,2], thisEmailList[i,1]))
}
[1] "joejoejt#gmeel.com Test, Joe"
[1] "jimmyadminj#gmeel.com adminintor, Admin"
You want to use the basic apply function in row-mode (second parameter is 1):
apply(data.frame(thisEmailList$user_name, thisEmailList$user_email),
1,
function(x) {
# send email to user x[1]
# whose email address is x[2] )
})
You can't use the normal data frame column references inside apply, so I create a temporary input data frame whose first column (x[1]) is the user_name and whose second column (x[2]) is the user_email.

R autocomplete from list without GUI

I am looking for a way to autocomplete an argument of a function while typing (i.e. with tab).
For example, let say I have a function f with an argument name and I want to be able to autocomplete name from a list of possible names c("AAA","BBBBB","C") and as I am typing on the terminal
f(name="A
if I hit tab then it should autocomplete to
f(name="AAA"
and continue typing more arguments the function may need.
The solution so far is defining the list with select.list:
f<-function(name=select.list(c("AAA","BBBBB","C")),graphics=FALSE),other arguments...)
and let the user select the name from the list that is displayed immediately after calling the function, but I want to avoid doing this since the list may be quite large.
PS I found the function select.list after reading the question
R Prompt User With Autocomplete
This kind of thing is best left to the editor of your choice.
However, R can perform partial matching on for named arguments using match.arg so you don't need to autocomplete anyway.
x <- function(x =c('aa','b')) return(match.arg(x))
x('a')
# [1] "aa"
x('b')
[1] "b"
x('c')
# Error in match.arg(x) : 'arg' should be one of “aa”, “b”

Resources