I'd like to take data of the form
before = data.frame(attr = c(1,30,4,6), type=c('foo_and_bar','foo_and_bar_2'))
attr type
1 1 ... moreI'd like to take data of the form
before = data.frame(attr = c(1,30,4,6), type=c('foo_and_bar','foo_and_bar_2'))
attr type
1 1 foo_and_bar
2 30 foo_and_bar_2
3 4 foo_and_bar
4 6 foo_and_bar_2
and use split() on the column "type" from above to get something like this:
attr type_1 type_2
1 1 foo bar
2 30 foo bar_2
3 4 foo bar
4 6 foo bar_2
I came up with something unbelievably complex involving some form of apply that worked, but I've since misplaced that. It seemed far too complicated to be the best way. I can use strsplit as below, but then unclear how to get that back into 2 columns in the data frame.
> strsplit(as.character(before$type),'_and_')
"foo" "bar"
"foo" "bar_2"
"foo" "bar"
"foo" "bar_2"
Thanks for any pointers. I've not quite groked R lists just yet. less
Given a vector of scores and a vector of actual class labels, how do you calculate a single-number AUC metric for a binary classifier in the R language or in simple English?
Page... moreGiven a vector of scores and a vector of actual class labels, how do you calculate a single-number AUC metric for a binary classifier in the R language or in simple English?
Page 9 of "AUC: a Better Measure..." seems to require knowing the class labels, and here is an example in MATLAB where I don't understand
R(Actual == 1))
Because R (not to be confused with the R language) is defined a vector but used as a function?
I'm pretty new to R programming. I'm using R studio, and all of a sudden it's no longer showing the workspace, it's only showing the console.
This is what it is supposed to look... moreI'm pretty new to R programming. I'm using R studio, and all of a sudden it's no longer showing the workspace, it's only showing the console.
This is what it is supposed to look like
And this is what mine looks like now.
In Eclipse, whenever the workspace gets out of wack, I can just reset the perspective and everything it back to normal. I can't figure out how to do that in R Studio.
The default layout seemed to disappear after I restarted my computer.
I need to write the equivalent of the following code in R but I'm not quite sure how to go about it:
def add(args):
result = args + args
return... moreI need to write the equivalent of the following code in R but I'm not quite sure how to go about it:
def add(args):
result = args + args
return result
The reason why is because for the platform I am using (Cloudera Data Science Workbench) models need a JSON input to be able to call them using an API key
So if I write a test model in R such as:
f <- function(x, y) {
return (x + y)
}
I cannot do a call like {"x" : 2, "y" : 4} using the httr package.
So I either need to make a dictionary like call for functions in R
OR
I am simply calling JSON incorrectly in which case could someone help me format that correctly for an API call
Thanks less
I've been using gsub("toreplace","replacement", myvector) to clean out data in R. While this works for commas and the like, removing "$" has no effect. So if I do... moreI've been using gsub("toreplace","replacement", myvector) to clean out data in R. While this works for commas and the like, removing "$" has no effect. So if I do gsub("$","",myvector) all the dollar signs remain in place.I think this is because $ is a special character in R. I tried escaping it "\$" but that yields the same result (no effect). And I couldn't find a resource on escaping special characters in R.Obviously I should do this in preprocessing. But I was wondering if anyone out there knew how to either a) escape special characters in R b) get rid of pesky $ in R directly. For science. less
In every instance in all of my classes where I reference R.id.something, the R is in red and it says "cannot resolve symbol R". Also every time there is R.layout.something it is... moreIn every instance in all of my classes where I reference R.id.something, the R is in red and it says "cannot resolve symbol R". Also every time there is R.layout.something it is underlined in red and says "cannot resolve method setContentView(?)". The project always builds fine. It is annoying to see this all the time. I have read many other questions on here about something similar but most involved importing projects from Eclipse. I am using what I believe to be the most recent version of Android Studio and the project was created with Android Studio and worked without any "cannot resolve R" problems. I would like to know what causes this if anyone knows. less
I've trained a tree model with R caret. I'm now trying to generate a confusion matrix and keep getting the following error:
Error in confusionMatrix.default(predictionsTree,... moreI've trained a tree model with R caret. I'm now trying to generate a confusion matrix and keep getting the following error:
Error in confusionMatrix.default(predictionsTree, testdata$catgeory) : the data and reference factors must have the same number of levels
prob <- 0.5 #Specify class split
singleSplit <- createDataPartition(modellingData2$category, p=prob,
times=1, list=FALSE)
cvControl <- trainControl(method="repeatedcv", number=10, repeats=5)
traindata <- modellingData2
testdata <- modellingData2
treeFit <- train(traindata$category~., data=traindata,
trControl=cvControl, method="rpart", tuneLength=10)
predictionsTree <- predict(treeFit, testdata)
confusionMatrix(predictionsTree, testdata$catgeory)
The error occurs when generating the confusion matrix. The levels are the same on both objects. I cant figure out what the problem is. Their structure and levels are given below. They should be the same. Any help would be greatly appreciated as its... less
I'm trying to figure out how saving works in R Studio.
When i create a new project, a .RProj file is created. Whenever I work in R Studio, Save and Save As are greyed out in the... moreI'm trying to figure out how saving works in R Studio.
When i create a new project, a .RProj file is created. Whenever I work in R Studio, Save and Save As are greyed out in the File menu. The only way I know how to create a .RProj file is when starting a new project.
In the environment section, I can see a floppy disk Save icon. When I click that, it creates a .RData file. When ever I want to save, I click on that save icon and overwrite the file.
Can someone please explain what the best practices are for saving when using R Studio and the key distinctions between the .RProj and .RData files? less
I am trying my hands at grabbing data from an API in R.
The API I am using is the Data Science Toolkit's street2coordinates.
Basically this API returns the coordinates for street... moreI am trying my hands at grabbing data from an API in R.
The API I am using is the Data Science Toolkit's street2coordinates.
Basically this API returns the coordinates for street addresses. I tried using it and it works fine when I pass just one address. Like This:
library(httr)
I am not sure how to pass multiple addresses to this function.
I tried doing this but the output is something I don't understand. It's a weird list.
addresses <- c("4600 Vegas Dr, Las Vegas, NV 89108","3600 Vegas Dr, Las Vegas, NV 89108")
url <- GET("http://www.datasciencetoolkit.org/street2coordinates/addresses")
Long story short, I am looking for a way to pass more than one address in the GET function. Is there a way to do this?
I'm working on an application that requires a great deal of stastical processing and output as images in a .net desktop application. The problems, including generating the output... moreI'm working on an application that requires a great deal of stastical processing and output as images in a .net desktop application. The problems, including generating the output images, seem like a natural fit for R http://www.r-project.org/
Is there a wrapper, API, SDK, or port that will allow me to call R from .net?
It seems like R is really designed to handle datasets that it can pull entirely into memory. What R packages are recommended for signal processing and machine learning on very... moreIt seems like R is really designed to handle datasets that it can pull entirely into memory. What R packages are recommended for signal processing and machine learning on very large datasets that can not be pulled into memory?
If R is simply the wrong way to do this, I am open to other robust free suggestions (e.g. scipy if there is some nice way to handle very large datasets)
I am working with a very large data set which I am downloading from an Oracle data base. The Data frame has about 21 millions rows and 15 columns. My OS is windows xp (32-bit), I... moreI am working with a very large data set which I am downloading from an Oracle data base. The Data frame has about 21 millions rows and 15 columns. My OS is windows xp (32-bit), I have 2GB RAM. Short-term I cannot upgrade my RAM or my OS (it is at work, it will take months before I get a decent pc).
library(RODBC) sqlQuery(Channel1,"Select * from table1",stringsAsFactor=FALSE)
I get here already stuck with the usual "Cannot allocate xMb to vector". I found some suggestion about using the ff package. I would appreciate to know if anybody familiar with the ff package can tell me if it would help in my case. Do you know another way to get around the memory problem? Would a 64-bit solution help? Thanks for your suggestions. less
Here are my codes, pretty standard but I am getting the error msg:
library(caret)
set.seed(32343)
modelFit = train(type~.,data=training,... moreHere are my codes, pretty standard but I am getting the error msg:
library(caret)
set.seed(32343)
modelFit = train(type~.,data=training, method='glm')
error msg:
Error in library(e1071) : there is no package called ‘e1071’
I am studying R end Data Science. In a question, I need to validate if a number in an array is even.
My code:
vetor <- list(c(1, 2, 3, 4, 5, 6, 7, 8, 9,... moreI am studying R end Data Science. In a question, I need to validate if a number in an array is even.
My code:
vetor <- list(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
for (i in vetor) {
if (i %% 2 == 0) {
print(i)
}
}
But the result is a warning message:
Warning message:
In if (i%%2 == 0) { :
a condição tem comprimento > 1 e somente o primeiro elemento será usado
Translating:
The condition has a length > 1 and only the first element will be used.
What I need, that each element in a list be verified if is even, and if true, then, print it.
In R, how can I do it? less
I would like to remove specific characters from strings within a vector, similar to the Find and Replace feature in Excel.
Here are the data I start with:
group <-... moreI would like to remove specific characters from strings within a vector, similar to the Find and Replace feature in Excel.
Here are the data I start with:
group <- data.frame(c("12357e", "12575e", "197e18", "e18947")
I start with just the first column; I want to produce the second column by removing the e's:
group group.no.e
12357e 12357
12575e 12575
197e18 19718
e18947 18947