Get more than 1000 observation for View() function - r

I'm working with RStudion and when I use the View() command I can only see the first 1000 rows.
Is it possible to get more than 1000 rows ? or less than 1000 rows ? is it possible to get a range observation like observation in 500 : 1000 ?
Thanks in advance.

It can happen:
Let's say that you have a data.frame called df which has 2000 rows and 2 columns. To view all of them you need to explicitly type on the console:
utils::View(df) #however this will open a new separate window to view all the records.
In order to view just 500:1000 records of the data.frame just do:
utils::View(df[500:1000,]) #i.e. use the standard way of slicing the data.frame in the function.
Hope this helps.

Related

R - how to use a function on a list of data frames

I have a little problem with my code. I hope you can help me :)
I used a function apply to create a list of 20 data frames (data about stock index returns, grouped by year and index - about three companies and the stock, for 5 years). And now I want to use function with two arguments (it calculates proportion of covariance of the returns for selected company and the stock to variance (for every year) - this is why I'm trying to group the data. How to do it... automatically, without manual typing code for every year and company?
I don't have any idea if I should use for loop or there is any other way...?
And the other thing is in which way can I delete uneccesary columns from list of data frames?
I'll be thankful for your help.
And sorry for my English :D
You may consider purrr::map_dfr(). The first argument will be your list of data frames, and the second the action to do with that data frame. The final result will be a single data frame uniting the result of all of the above. Your code will likely look something like this:
purrr::map_dfr(list_of_dataframes, function(x) {...})
Within the bracketes, instead of ... insert your logic. In that context, x will be the same as list_of_dataframes[[1]], and then list_of_dataframes[[2]], etc.
You may want to consult the documentation of the package purrr for further details.

Using For Loop in R to loop through a dataframe

I have a function called Produce_Output. It takes an X variable and a Y variable then in R carries out some calculations, SQL data retrievals, saves a plot to a file location etc. the function itself doesn't produce anything but triggers other actions.
I want to run this function through a data frame which has been setup for it. The dataframe has 8464 obs and 2 variables. I would like to use the function and pass each 2 variables to the function an observation at a time.
calling the function as follows
for (Data_To_Process) {
Produce_Output(TableA$Column1, TableA$Column2)
}
I get the following error
Error in $<-.data.frame(*tmp*, "OND", value = c(3379L, 3121L,
1699L, : replacement has 8464 rows, data has 3
I read a post on here about the data having NULLs, I've checked that and it doesn't. I also don't understand what it replacing what with. I just want it to process the first row, then the next... then the next... as I said the function has no output but triggers other procedures using the two values inserted. Any help would be appreciated.
Rui Barradas - You are perfectly correct that was the issue. I was aware of the index method for the loop but had only access to instances where one column was being used so didn't understand how to reference other columns in the syntax. Thanks for your help
"You are passing the entire columns, not rows. It could be something like for(i in 1:nrow(TableA)){Produce_Output(TableA$Column1[i], TableA$Column2[i])}"

How to create a new column filtering data by date

I need to sort my data by date. Previously I had one dataset and used select and filter to create two separate datasets, one with data from June 30 or earlier and the other with data from July 1 or later. However, my problem is that I seem to have lost some rows during this process - I went from 1390 rows in my original dataset to 1335 rows between the two new datasets. I can't figure out what happened.
What I am trying to do now is use my original dataset, ethica_surveys and create a new column. I want to call this column pre_post. I know how to create a new column, but I want to filter the data into this column based on my date parameters. So the rows containing pre should be dated June 30 or earlier, and those containing post should be dated July 1 or later. I am filtering based on the variable response_time, but I am just unsure of how to code this in RStudio.
Thanks in advance for any help you can provide.
This seemed to work after a lot of trial and error.
ethica_surveys$pre_post <-
if_else(ethica_surveys$response_time > as.Date("2018-07-
01"),"post","pre")

Conditional Sum For Multiple Datasets in RDLC

I'm trying to sum up values based on the 'Description' column of a dataset. So far, I have this
=Sum(Cdbl(IIf(First(Fields!Description.Value, "Items") = "ItemA", Sum(Fields!Price.Value, "Items"), 0)))
But it keeps giving me an error saying that it "contains a First, Last, or Previous aggregate in an outer aggregate. These aggregate functions cannot be specified as nested aggregates" Is there something wrong with my syntax here?
What I need to do is take something like this...
Item | Price
Item A | 400.00
Item B | 300.00
Item A | 200.00
Item A | 100.00
And I need to get the summed Price for 'ItemA' - 700.00 in this case.
All of the answers I've found so far only show for a single dataset OR for use with a tablix. For example, the below code does not work because it does not specify the scope or the dataset to use.
=Sum(Cdbl(IIf(Fields!Description.Value) = "ItemA", Sum(Fields!Price.Value), 0)))
I also can't specify a dataset to use, because the control I'm loading into is a textbox, not a tablix.
If anyone else sees this and wants an answer, I ended up returning a count back of what I needed on another dataset. The other option I was thinking would possibly be to create a 1x1 tablix, set the dataset, and then use the second bit of code posted.

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!

Resources