Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

printing asterisks in R #3

Open
aspri951 opened this issue Jan 21, 2017 · 3 comments
Open

printing asterisks in R #3

aspri951 opened this issue Jan 21, 2017 · 3 comments

Comments

@aspri951
Copy link
Collaborator

I am also stuck on question 9 (drawing a box). My (smaller) goal: write code that returns a line of asterisks with no quotation marks around them. Problem, as I understand it: R views "*" as an operator (multiplication), so it returns an error whenever it sees an asterisk in a context that is NOT "multiplying numbers." Making the asterisk into a character fixes this, but means my line is full of quotation marks:

star.line <- function(w){
  top.of.box <- rep("*", w)
  return(top.of.box)
}
#works, but has quotations around the asterisks

star.line <- function(w){
  top.of.box <- "*"
  return(rep(top.of.box, w))
}
#same result. Try using print?

star.line <- function(w){
  for(i in 1:w){
    print("*")
  }
}
#prints vertical row of asterisks in quotations

Question: What R function would allow me to print an asterisk (or where would I look to find such a function)? I've looked through all the terms I defined in Assignment 1 and considered matrix, table, the par function bty, but none seem to be useful. Maybe I'm missing something.

@willpearse
Copy link
Member

willpearse commented Jan 22, 2017 via email

@aspri951
Copy link
Collaborator Author

I made a box! Took an hour, but if I could finish every problem in only an hour life would be good indeed...

Question: How can I go about trying to find a function I've never seen before (other than you just telling me)? In the future I might need a function that's not in assignment #1, and as I mentioned, it's these basic syntax/language fluency problems that keep getting me stuck, not the programming itself. Once I had the "cat" function, writing a function to draw a box was simple! Clearly what I'm lacking is a) a good resource for fixing my basic language/syntax ignorance, and/or b) the skill to sort through resources like stack overflow without getting myself into even deeper trouble due to my aforementioned language ignorance.

... I'm guessing there's not a short or easy answer to this question. Sorry! Either way, hopefully it's useful to know where I'm continually getting stuck.

@willpearse
Copy link
Member

willpearse commented Jan 24, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants