

- COMMAND FOR CREATING SUBSET DATA IN R STUDIO MAC HOW TO
- COMMAND FOR CREATING SUBSET DATA IN R STUDIO MAC CODE
I'm probably missing something silly, but I don't know how to fix this and I couldn't find a solution using Google. My_columns$text <- as.character(as.factor(my_columns$text)) When I manually change it to character using When I executed class(my_columns$text) it returned 'factor'. My_columns <- read.csv("tweets.csv", sep=" ")Īfter executing this, I get the dataframe and everything seems to work.īut when I execute your code, I get an error message telling me that there were 50 or more warnings, all saying 'probable complete loss of accuracy in modulus'.ĭo you have any idea why this might be happening? Perhaps it has something to do with the class of the columns, because for another assignment in this data frame we had to add an extra column with the amount of characters per tweet, and this used to work, but now all of a sudden it's telling me that the column 'text' isn't a character vector. Write.table(my_columns, "tweets.csv", row.names = FALSE, col.names = TRUE, sep =" ") # before we can use the data frame in Access we need to delete all quotation marks from the text field # we only need these columns for our analysis My_columns <- subset(df, select=c("text","created","screenName","retweetCount","isRetweet","id")) T_stream <- searchTwitter('*subject of interest*', resultType="recent", n=500)ĭf <- do.call("rbind", lapply(t_stream, as.ame)) Setup_twitter_oauth(ck, cs, access_token = at, access_secret = as)
COMMAND FOR CREATING SUBSET DATA IN R STUDIO MAC CODE
The code the teacher has provided us with to set up the assignment is the following: require(twitteR)

It's probably my fault, so I hope you might be able to help me a bit further. I'm having some trouble getting these codes to work. I'll tell the teacher that this is a unnecessary workaround. I'm not particularly skilled at R, I'm just learning to use it right now, but this was the assignment we were given so I can't really do much about it, unfortunately. If it was me I would turn in two answers to this assignment - the stupid one they've asked for and the good one that's actually worthwhile. Hopefully it's obvious why - because you can accomplish the same thing with a single line! If you worked for me and turned in either of those, I would fail your code review so goddamn hard. Or dare I say even this fucking monstrosity: new <- ame()

What they want to see is something like this: yn <- vector() Instead, your teacher wants you to do it some ass-backwards way that will be slow as hell since it will grow the data structure, and which isn't very idiomatic R. That's it! One goddamn line! Isn't that amazing? Or with dplyr a little more stylishly as another commenter pointed out: new <- dplyr::filter(df, id %% 2 = 0) In base R, this task would be accomplished like this (assuming your starting data frame is called df and your target is called new): new <- df This assignment falls into both of those traps! Growing Objects is Chapter 2, and Failing to Vectorise is Chapter 3. There is a book called the R Inferno which is basically a tongue-in-cheek guide to all the easy-to-make mistakes in R. R uses what's called "vectorised operations" specifically to avoid exactly the kind of thing you're being told to do, because doing it that way is slow as hell with the way R works under the hood, and it also doesn't suit the style of idiomatic R. The reason it's dumb is because R deliberately and consciously doesn't want you to use a for loop and an if-else to solve this problem.
