Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I got data with ASCII form.
I ran it with R, and these data have * marked when it is under other condition.
enter image description here
V1, V2, V3, V4, V5 don't mean anything different. All that matters is to classify between *-ed things.
I tried c(V1,V2,V3,V4,V5) but it returns only the levels.
I have no idea. Help me with it.
Question. Can I specify *-ed things via some code?
Is there a way to make these columned things in one data?
Select the values marked with *. I guess these values come with the symbol from the original file, right?
In this case use:
position <- grep('\\*', as.matrix(distress[]))
selectedValues <- as.matrix(distress[])[position]
numericValues <- as.numeric(gsub('\*', '', selectedValues))
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 days ago.
Improve this question
I have a problem with the coding of some variables. I am working on data for Lebanon on R on two different datasets, the World Value Survey and the Arab Barometer. Regardless of the dataset I am using, when I try to code a variable referring only to one country (in this case Lebanon), the values of the variable at the end of the coding are entirely wrong.
I have tried the same coding with other variables and with another dataset, but the problem remains, and the values are still much larger than they should be.
As can be seen from the values in the 'table' command, the values after encoding are very different.
As a beginner, I'm sure my question will be trivial, but I'm asking for help to unblock the situation.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
When I use correlation function in RstudioThis I get below error message:
The dataset that I have imported is show below and V1,V2 are given by default to the columns:
There are two ways:
1) Attaching the data:
attach(data1)
And then this code should work:
cor(V1, V2)
2) Using $ for accesing columns in a dataframe
cor(data1$V1, data1$V2)
So, if I got you correctly, you want to find correlation between variables V1 and V2 in the dataframe data1. To refer to the column in the dataframe a $ sign is used. Then your code will look like:
cor(data1$V1,data1$V2)
or, if you want, you can also use with() function, which would narrow down the namespace to particular dataframe data1:
with(data1, cor(V1, V2))
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I need to replace number values with something that makes more sense to the reader.
Value “-0.95197” represents “18-24” age group in the given table.
What would be the best way to go about this for all columns?
Your question is a little unclear. Are you trying to rename the header of each column in a data.frame? If so, try this, where df is the name of your data.frame. You need one piece of text for each column.
names(df) <- c("your", "header", "names", "go", "here")
If this is not what you want, then you need to provide more info.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am trying to convert factors from a data-frame to numeric using the commands
data[] <- lapply (data, function(x) as.numeric(as.character(x))
But it keeps asking me for more coding. What am I doing wrong?
The data-frame is named data and it consists of 50 rows and 2 columns. Will this command change every variable in numeric right? Or shall I do something else?
screenshot after using 'dput' at http://imgur.com/Sde9QSk.png
Shouldn't you add ) at the end of your code?
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a data frame that has some empty entries. I set the
options(stringsAsFactors = FALSE)
so that I can change the empty cells. I then wrote the following code:
apply(my_data[,6:65],2, function(x) x[which(x=='')]<-0)
, hoping that it replaces all the empty cells with zeros. But it isn't working!
Note that my_data has 65 columns and columns 1:5 contain string.
Thanks in advance
No need to use apply, just use [<- with logical indexing
my_data[my_data==""] <- 0