I'd like to rename data inside of a dataframe, how can I do it? is there a way to run multiple lines of code in R with the press of one button? - dataset

I've got a very simple dataframe with two columns: one is filled with characters (as in names, specifically crop types) and the other one with numbers (areas).
The first column (crop types) is in Italian but I need the names to be in English.
I know I might use the gsub() function to manually rename each one of them but I'm working with several graphs and the code would definitely become too long.
So my questions are:
Is there a quicker way to rename entries of a dataset (in this case, all entries of a column)?
And in case the answer is no, how may I run multiple lines of code in R at once?
Thank you :)

Related

How do I count the number of filled-in rows of a sheet based on the contents of a column?

Disclaimer: I am completely self-taught in google sheets
I have a sheet with columns for Date, Place, Title, etc. I am attempting to count how many rows have all their cells filled out, but only want to add up the rows within a certain time period (i.e. based on the "date" cells, which are column A.)
=SUM(ARRAYFORMULA(AND(
ISBETWEEN(A9:A,DATE(2022,1,21),DATE(2022,4,1)),
ISTEXT(B9:B)=ISTEXT(C9:C)=ISTEXT(D9:D)=TRUE)))
Currently I have this formula, which relies on an "AND" function to check that both the "ISBETWEEN" and "ISTEXT" criteria are met. However, I think this is keeping "ARRAYFORMULA" from working (I originally used "SUMPRODUCT", but that didn't work either.) If that isn't the problem, the fact that the different references aren't somehow logically connected makes wonder if this would method would even work to begin with...
So, what functions could I use to accomplish my goal?
I would prefer to contain all of this in one formula, but at this point I'd be fine utilizing a separate hidden sheet if what I'm doing isn't possible in just one cell.
(I've done my best to try and find if this has already been asked, but honestly I'm not sure how to properly phrase this, so sorry if this is a duplicate.)
try:
=COUNTA(IFNA(FILTER(B9:B; B9:B<>""; C9:C<>""; D9:D<>"",
A9:A>="2022-1-21*1"; A9:A<="2022-4-1"*1))
or use:
=SUMPRODUCT(B9:B100<>""; C9:C100<>""; D9:D100<>"";
A9:A100>="2022-1-21"*1; A9:A100<="2022-4-1"*1)

MATLAB strings in arrays

I know that I am pretty confused about arrays and strings and have tried a bunch of things but I am still stumped. I have groups of data that I am pulling into various arrays. For example I have site locations coming from one source. Numerous cores can be at a single location. The cores can have multiple depths. So I am pulling all this data together in various ways and pushing it out into a single excel file for each core. I create a filename based on location id and core name and year the core was sampled. So it might look like ‘ID_14_CORE_Bu-2-MT-1991.xlsx’ and I am storing it to use with a xlswrite statement in a variable called “filename.” This is all working fine.
But now I want to keep track of what files I have created and when I created them in another EXCEL file. So I was trying to store the location, filename and the date it was processed into some sort of array so that I can use the xlswrite statement to push it all out after I have processed all the locations/cores/layers that might occur in the original input files.
As I start the program and look in the original input files I can figure out how many cores I have so I wanted to create some sort of array to hold the location, filename and the date together. I have tried to use a cell array (a = cell(numcores,3)) but that does not seem to work. I think I am understanding that the filename is actually a string array so each of the letters is trying to be assigned to a separate cell instead of just the cell in the second column.
I also have had problems trying to push the three values out to the summary EXCEL file as each core is being processed but MATLAB tends to treat single dimensional arrays as a row rather than a column so I am kind of confused there.
Below is what I want an array to end up like…but since I am developing the filename on the fly this seems to be more challenging.
ArraytoExcel = [“14”, “ID_14_CORE_Bu-2-MT-1991.xlsx”,”1/1/2018”;
“14”, “ID_14_CORE_Bu-3-MT-1991.xlsx”,”1/1/2018”;
“13”, “ID_13_CORE_Tail_33-1992.xlsx”,”1/1/2018”;]
Maybe I am just going about this the wrong way. Any suggestions would help.
Your question is a little confusing but I think you want to do something like the following. The variables inside of my example are static but from your question it sounds like you already have these figured out somehow.
numcores = 5; %.. Or however, you determine what you are procesing
ArraytoExcel = cell(numcores ,3);
for ii = 1:numcores
%These 3 things will need to determined by you in the loop
% and not be static like in this example.
coreID = '14';
filename = 'ID_14_CORE_Bu-2-MT-1991.xlsx'; %
dataProc = datestr(now,'mm/dd/yyyy');
ArraytoExcel(ii,:) = {coreID,filename,dataProc};
end
xlswrite('YourOutput.xls',ArraytoExcel)

Parsing multiple dates from cell

I've got a spreadsheet that, for goofy reasons, has two columns next to each other in each of which is a series of dates, separated by ctrl-rtn linefeeds. They amount to a list of start/stop periods. There are reasons it's done this way, and will probably continue to be (I am open to other suggestions).
Given this structure, I'd like to be able to pull out the periods and/or period lengths. That is, given:
1/1/2015 1/3/15
1/15/15 1/20/15
2/3/15 2/7/15
(in only two adjacent cells) I'd like to be able to pull out at least:
2
5
4
and perhaps optionally break it up into six different cells (note that the lists will be variable lengths). This is much less important.
I am having a hard time figuring out how to even approach this. If I was in VBA I could regex it easy-peasy. I'm utterly new to Spreadsheet Scripts. Thanks so much for any help.
You should be able to split each cell (say A1) into three with:
=split(substitute(A1,char(10),","),",")
Repeat for the next (say A2), format as dates and in B3 and copied across to the right to suit:
=B2-B1

Array multiplication in Excel

In my excel document I have two sheets. The first is a data set and the second is a matrix of the relationship between two of the variables in my data set. Each possibility of the variable is a column in my matrix. I'm trying to get the sum of the products of the elements in two different arrays. Right now I'm using the formula {=SUM(N3:N20 * F3:F20)} and manually changing the columns each time. But my data set is over 800 items...
Ideally I'd like to know how to write a program that reads the value of the variable in my dataset looks up the correct columns in the matrix, multiplies them together, sums the products, and puts the result in the correct place in my data set. However, just knowing the result for all the possible combinations of columns would also save me alot of time. Its an 18x18 matrix. Thanks for any feedback!
Your question is a little bit ambiguous but as far as i understand your question you want to multiply different sets of two columns in the same sheet and put their result into the next sheet, is it so? if so, please post images of your work (all sheets). Your answer is possible even in Excel only without any vba code, thanks.
you can also use =SUMPRODUCT(N3:N20,F3:F20) for your formula instead of {=SUM(N3:N20 * F3:F20)}

Matlab Multidimensional Arrays with string + Exporting to Excel

i have a code that works on all files in folder and analyise it and come then export results into excel sheet.
My question is, by the end i alot of excel sheets and i need to combine them all together (i also need them separate) so i do this manualy and its really painfull and time wasting !
So i want to ask is there a way to create an array to save the results of each analysis my code process and export all at the end to one excel file.
Example of my code Workflow:
Read files in current dir
Open files one by one.
Do math equations and get results into 2 arrays amp[] signal[] (both are equal in size)
Export results into Excel using
xlswrite([b '.xls'],[amp' signal'],1);%%b=file name (example.avi ==> example.avi.xls)
And so on.
So i want to save the results after that to array with the filename and at the end past all into 1 excel sheet with the file name on top of each column :)
I dont know why i'm having a brain block on how to do it !
Thanks alot for your help in advance
Xlswrite supports that you give a start point or range where you want to put your data. See Xlswrite.
You can quickly calculate the column name using this.
But you must be aware that excel only supports 255 columns and 1024 rows in a sheet. This happened often to me and then one gets a very uninformative error.

Resources