Change values that aren't times into missing values in R - r

I have one variable in a data frame that lists different times, but there are some values that are actually dates. It would look something like:
Data<-c("0:03","1:15","20:37","27-Jun-12","3:55","5-May-13")
I would like to change those date values into missing values without touching any of the times. Any help is appreciated.

There are a lot of ways to do this but here is one. If the data has a dash change to NA:
Data[grepl("-", Data)]<-NA

Related

R - Can I have a matrix with different number of columns for rows?

This might be a stupid question. I have some 'NA' in a matrix, I need to put this matrix into jags model, but I want to remove those NA. Can I remove only NA but keep the rest of the data?
My data looked like the picture below. Can I have rows with different column numbers?
You cannot.
You need to impute these missing values or remote either the column or the row entirely.
Imputing missing values is as complicated as you want it to be. You'd be best of looking into the first few google searches on the topic or just using the mean value of the column.

Subsetting rows, changing values, and placing them back into matrix?

I hope this has not been answered, but when I search for a solution to my problem I am not getting any results.
I have a data.frame of 2000+ observations and 20+ columns. Each row represents a different observation and each column represents a different facet of data for that observation. My objective is to iterate through the data.frames and select observations which match criteria (eg. I am trying to pick out observations that are in certain states). After this, I need to subtract or add time to convert it to its appropriate time zone (all of the times are in CST). What I have so far is an exorbitant amount of subsetting commands that pick out the rows that are of the state being checked against. When I try to write a for loop I can only get one value returned, not the whole row.
I was wondering if anyone had any suggestions or knew of any functions that could help me. I've tried just about everything, but I really don't want to have to go through each state of observations and modify the time. I would prefer a loop that could easily go through the data, select rows based on their state, subtract or add time, and then place the row back into its original data.frame (replacing the old value).
I appreciate any help.

Comparing dates in a cell

I am trying to do a sumifs in Google Sheets that sums based on a number of variables held in cells. I want to be able to vary the dates in two cells to change the range that is summed. My formula looks like:
=SUMIFS(D2:D500,A2:A500,">8/01/15",A2:A500,"<9/01/15",F2:F500,C1012)
I want to be able to replace the two dates with cells. When I do, I get a formula parse error. I have seen a lot of questions about doing this for formatting, but not in this context.
Can anyone help?
Assuming your dates are in I1 and J1 please try:
=SUMIFS(D2:D500,A2:A500,">"&I1,A2:A500,"<"&J1,F2:F500,C1012)

In R: Getting matching values within a row of a data frame

I think my problem is less difficult than it seems to me right now:
In R, I have a data frame with several columns. Two of them are called "PlotId" and "Landuse":
PlotId Landuse
---------------------
000AEG01 Wiese
000AEG02 Weide
000AEG03 Maehweide
000AEG04 ...
"PlotId" contains 50 rows with values from "000AEG01" to "000AEG50", "Landuse" contains three levels: "Wiese", "Weide" and "Maehweide".
For another problem, which I try to solve, I simply need to get the "Landuse"-value for the corresponding "PlotId"-row. SO, I need a command that gives me the information: "Plot 000AEG01 corresponds to Landuse Wiese." And so on for all the other rows, so I probably need to write a loop for that. This information, I would like to get as an object, which I can use then within another loop. I hope, you get what I mean and can help me!
Thanks a lot in advance!

Trouble getting my data into wide form with the reshape package

I am currently analysing a rather large dataset (22k+records) and am having some trouble getting the data into a wide format (with one row corresponding to each observation, and columns representing variables).
The data came in two CSV files, one giving demographics and the other giving participants probability ratings to a number of questions. Both of these CSV files were in long format.
I have used the reshape (and reshape2 for speed) packages to attempt to solve my problem. The specific issue i am having is the following.
I have the participants probability ratings in the following form (after one successful reshape).
dtf <- read.csv("http://dl.dropbox.com/u/8566396/foobar.csv")
Now, the format i would like my data to be in is as follows:
User ID Qid1, ....Qid255 Time, with the probabilities for each question in the questions corresponding column.
I have tried a loop and apply to put the values into a new data frame, and many variations of melt and cast. I have also tried the base reshape function, but all to no avail.
In the past, i've always edited my CSV files directly, but this is not an option with the size of this file (my laziness when it comes to data manipulation within R has come back to haunt me).
Any advice or solution you can give to avoid me having to do this by hand would be greatly appreciated.
Your dataset has 6 rows, 3 of which have the column "variable" equal to "probability" and 3 of which have that column equal to "time". You want to have probability be the value of each, and time be added onto the right.
I think there's a difficulty in making this work for you because what you want to do isn't clear. You have values for each UID-Time-X### cell, and values for each UID-Prob-X### cell. Therefore, you have to discard information to get it into your preferred format (UID-Time-X### with probabilities as the values). It seems to me like you're treating time as an ID variable, but it's storing values like a content variable.
To avoid discarding any data, your output would have to look something like:
UID Time1 Time2 Time3 Prob1 Prob2 Prob3
Which is simply reshaped wide.

Resources